如何停止基于CSS值的jquery动画?
So, I have two divs: #div1 and #div2. I want '#div2' to disappear when '#div1' has the CSS value: top = 0px.
我有两个div: #div1和#div2。当#div1的CSS值为:top = 0px时,我希望#div2消失。
Here is the CSS:
CSS:
#div1 {
top: 0px;
}
#div2 {
display: block;
}
if ( $('#div1').css('top') == '0px' ) {
$("#div2").hide();
} else {
$("div2").fadeIn();
}
$("div2").click(function(){
$("#div1").animate({top:"+=315px"}, "slow");
});
The problem I am running into is that I'm changing that CSS value (for #div1) via Javascript and for this reason, my js doesn't acknowledge the change and doesn't make the div disappear (I think). Is there any way to make #div2 disappear when #div1's CSS property top = 0 and reappear whenever it is changed? Or is there a better way to implement this?
我遇到的问题是,我正在通过Javascript修改CSS值(对于#div1),出于这个原因,我的js不承认这个更改,也没有使div消失(我想)。当#div1的CSS属性top = 0时,是否有办法使#div2消失,并且当它被更改时重新出现?或者有更好的方法实现它吗?
3 个解决方案
#1
3
rather than using this use method .position()
而不是使用这个use方法。position()
<script>
var p = $("#div1");
var position = p.position();
alert( "left: " + position.left + ", top: " + position.top );
</script>
more detail about this : http://api.jquery.com/position/
更多细节:http://api.jquery.com/position/
更多相关文章
- 整理:Google jQuery 引用地址大全和方法(转)
- JQuery属性与样式――.val()和增加样式.addClass()
- 如何使用ajax GET或POST方法将数据传递到amazon lambda节点。js
- 关于jQuery获取html标签自定义属性值或data值
- Jquery常用技巧和方法收集
- Chosen 基于jquery的选择框插件使用方法
- jQuery $ajax 传中文数据到action乱码解决方法
- JQuery 的选取元素 和 方法
- jquery为属性过滤器动态添加值?