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/

更多相关文章

  1. 整理:Google jQuery 引用地址大全和方法(转)
  2. JQuery属性与样式――.val()和增加样式.addClass()
  3. 如何使用ajax GET或POST方法将数据传递到amazon lambda节点。js
  4. 关于jQuery获取html标签自定义属性值或data值
  5. Jquery常用技巧和方法收集
  6. Chosen 基于jquery的选择框插件使用方法
  7. jQuery $ajax 传中文数据到action乱码解决方法
  8. JQuery 的选取元素 和 方法
  9. jquery为属性过滤器动态添加值?

随机推荐

  1. 在Eclipse中使用aar文件
  2. Android百度地图开发之获取apikey
  3. Android通过蓝牙获取通讯录
  4. ArrayMap的使用与详解
  5. android中的shape使用之android:angle
  6. TextView 设置行高并垂直居中
  7. Retrofit2,okhttp3 通过拦截器(Intercepto
  8. Android 仿微信通讯录列表侧边栏
  9. Android 修改用户图像笔记
  10. Android Service使用方法--简单音乐播放