【问题标题】:Incrase / decrase div size with 1 px on click button [closed]使用 1px onclick 按钮增加/减少 div 大小 [关闭]
【发布时间】:2012-12-03 06:55:48
【问题描述】:

我制作了一个网站,其中包含 PVC 窗户和门 PVC 产品。 我想用计算器制作订单页面。它正在工作,但我现在需要为窗口的配置设置动画。(例如:http://orasvirtual.ro/images/a.JPG) 所以,默认的窗口大小是 250px 高和 350px 宽。我做了4个按钮: (例如:http://orasvirtual.ro/images/b.JPG) 增加高度,减少高度,增加宽度和减少宽度。 到现在为止我已经做了这个,但是如何增加/减少按住 x 秒的点击。

谢谢大家

好的,到现在为止我已经做到了,感谢 NullPointer:

html:

<div  id='divid'>div</div>
<button id="inch" >+ h</button>
<button id="dech" >- h</button>
<button id="incw" >+ w</button>
<button id="decw" >- w</button>

jquery:

$("#inch").click(function(){

var height = $("#divid").height()+1; //to decrease just -1 instead of 1

$("#divid").height( height );
})
$("#dech").click(function(){

var height = $("#divid").height()-1; //to decrease just -1 instead of 1

$("#divid").height( height );
})
$("#incw").click(function(){

var width= $("#divid").width()+1; //to decrease just -1 instead of 1

$("#divid").width( width );
})
$("#decw").click(function(){

var width= $("#divid").width()-1; //to decrease just -1 instead of 1

$("#divid").width( width );
}) 

【问题讨论】:

标签: php jquery


【解决方案1】:

您无法更改window 对象的宽度/高度,但可以更改body 元素的宽度和高度。

$('#increaseWidth').click(function(){
    $('body').width(function(i, w){
       return w + 1
    })
})

$('#decreaseHeight').click(function(){
    $('body').height(function(i, h){
       return h - 1
    })
})

http://jsfiddle.net/HsHj8/

【讨论】:

    【解决方案2】:

    如果窗口元素是$(window),使用下面的代码

    增加宽度:

    $(window).width($(window).width() + 1 + "px")
    

    减小宽度:

    $(window).width($(window).width() - 1 + "px")
    

    增加高度:

    $(window).height($(window).height() + 1 + "px")
    

    降低高度:

    $(window).height($(window).height() - 1 + "px")
    

    谢谢

    【讨论】:

      【解决方案3】:

      在大多数情况下你不能这样做。

      来源:

      从 Firefox 7 开始,网站不再可以根据以下规则更改浏览器中窗口的默认大小:

      1. 您无法调整不是由 window.open 创建的窗口或选项卡的大小。
      2. 当窗口或选项卡位于具有多个选项卡的窗口中时,您无法调整其大小。

      对于某些支持的浏览器,您可以使用以下方法来调整浏览器窗口的大小。

      window.resizeTo(w,h);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-09
        • 1970-01-01
        • 2018-05-23
        • 2012-09-12
        • 2014-08-06
        • 2020-09-21
        相关资源
        最近更新 更多