jquery,怎样监听整个页面的变化

jquery,怎样监听整个页面的变化,第1张

方法一:在标签上加入  onLoad="" onResize=""  方法  写上对应的方法即可

方法二:window.onresize=function(){///.....} 在方法里面写上对应的代码即可

<script>  

function adjust(obj){  

   var div = document.getElementById("pad")  

   var txt = document.getElementById("txt")  

   var w  = document.body.clientWidth  

   var h  = document.body.clientHeight  

   div.style.width = w/3  

   div.style.height = h/3  

   txt.style.width = w/6  

   txt.style.height = h/6  

}  

window.onload=function(){  

  window.onresize = adjust  

  adjust()  

}  

</script>  

<body style="margin:0pxheight:0px">  

<div id="pad" style="background:redzoom:1margin:0pxheight:0px">  

    <input type="text" id="txt">  

</div>  

</body>

给你推荐一个jquery重新封装resize代码,可以监听几乎所有html标签,比如text、p、div、span等。$(function(){

// Bind the resize event. When any test element's size changes, update its

// corresponding info div.

$('.test').resize(function(){

var elem = $(this)

// Update the info div width and height - replace this with your own code

// to do something useful!

elem.closest('.container').find('.info')

.text( this.tagName + ' width: ' + elem.width() + ', height: ' + elem.height() )})// Update all info divs immediately.

$('.test').resize()

// Add text after inline "add text" links.

$('.add_text').click(function(e){

e.preventDefault()

$(this).parent().append( ' Adding some more text, to grow the parent container!' )})// Resize manually when the link is clicked, but only for the first paragraph.

$(this).parent().resize()})})看一下官方介绍吧,里面有几个例子!jquery resize event


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11748359.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存