fadeTo与Jquery在Retina Macbook Pro上的Chrome中无法正常工作

时间:2015-03-18 04:58:31

标签: javascript jquery css google-chrome retina-display

我尝试使用jQuery淡出滚动div(而不是主窗口)中的元素,因为它们滚出视图。我正在使用fadeTo函数并在用户滚动时检查元素的位置。

See this stackoverflow thread for what I'm basing my code on

我的非视网膜监视器(使用Chrome)似乎一切正常。顶部元素正在滚动div的顶部淡出,就像它应该的那样。

然而,当我使用我的macbook pro w / retina显示器执行相同的操作时,我会得到奇怪的行为。对于滚动div中的某些元素(不是全部),fadeTo动画仅淡化div的一部分(底部)。上半部分(或更多部分)没有变化。

编辑:WAS ABLE TO MAKE A DEMO(尝试在显示器与视网膜屏幕上观看演示)。

知道为什么会这样吗?为什么我的视网膜屏幕上的表现与我的显示器上的表现不同(两者都使用相同版本的Chrome)?

我还应该提到所有这些html都被注入到现有的网页中,因此滚动div位于页面顶部的右上角(固定位置)。我正在构建Chrome扩展程序......我的代码:



$('#volleyThreadDiv' + objectId).scroll(function() {
    console.log('userDidscroll...');
    $('.volleyComment').each(function () {
        var height = $(this).css('height');
        var heightNumeric = height.substring(0, height.length - 2);
        heightNumeric = Number(heightNumeric);
        if ($(this).position().top + heightNumeric < 130) {
            $(this).stop().fadeTo(0, 0.2);
        } else {
            $(this).stop().fadeTo(0, 100);
        }
    });

    $('.volleyReply').each(function () {
        var height = $(this).css('height');
        var heightNumeric = height.substring(0, height.length - 2);
        heightNumeric = Number(heightNumeric);
        if ($(this).position().top + heightNumeric < 130) {
            $(this).stop().fadeTo(0, 0.2);
        } else {
            $(this).stop().fadeTo(0, 100);
        }
    });
});
&#13;
#volleyDiv {
	position:fixed;
	top: 20px;
	right: 30px;

	padding: 10px;

	z-index: 999999999999999999999999999;

	box-sizing: initial;
	background: none;
	border: none;
}

.volleyThreadDiv, #volleyActivityDiv {
	position: static;
	display: none;
	max-height: 300px;
	overflow-y: scroll;
	background: none;
	border: none;
}

.volleyThreadDiv::-webkit-scrollbar, #volleyActivityDiv::-webkit-scrollbar {  
    background-color: transparent;
}

.volleyComment, .volleyReply {
	margin: 5px 5px 5px 5px;
	padding: 5px;

	border: 2px solid #63c5e2; /* blue border */
	border-radius: 8px;

	width: 155px;

	background: white;

	box-shadow: 0px 2px 1px #888888, -2px 2px 1px #888888;
	box-sizing: initial;
}

.volleyCommentStatus, .volleyReplyStatus {
	padding: 0px 5px 0px 5px;
	margin: 0px 0px 0px 0px;

	font-family: 'Avenir Next', Helvetica, sans-serif;
	font-size: 12px;
	font-weight: normal;
	color: #262626;

	line-height: 1.5;

	word-wrap: break-word;
}

.volleyCommentStatus, .volleyReplyStatus {
	text-align: left;
}

.volleyCommentStatus > a:link, .volleyReplyStatus > a:link, .volleyCommentStatus > a:visited, .volleyReplyStatus > a:visited {
	font-family: 'Avenir Next', Helvetica, sans-serif;
	font-weight: normal;
	color: #63c5e2 !important;
	text-decoration: none !important;
	border: none;
	padding: none;
	margin: none;
	background-color: white !important;
}

.volleyCommentStatus > a:hover, .volleyReplyStatus > a:hover {
	font-family: 'Avenir Next', Helvetica, sans-serif;
	font-weight: normal;
	color: gray !important;
	text-decoration: none !important;
	border: none;
	padding: none;
	margin: none;
	background-color: white !important;
}

.volleyCommentAuthor, .volleyReplyAuthor, .volleyCommentDate, .volleyReplyDate {
	font-family: 'Avenir Next', Helvetica, sans-serif;
	font-style: italic;
	font-size: 10px;
	font-weight: normal;
	color: gray;

	margin: 0px 5px 0px 0px;

	line-height: 1.5;
}

.volleyReplyAuthor {
	clear: both;
	text-align: left;
	padding: 0px 5px 0px 5px;
}

.volleyCommentAuthor {
	clear: both;
	text-align: left;
	padding: 0px 5px 0px 5px;
}

.volleyCommentDate, .volleyReplyDate {
	float: right;
	margin: 0px 5px 0px 7px;
}

.volleyCommentReply {
	float: right;

	border: 2px solid #63c5e2; /* blue border */
	border-radius: 8px;

	background: #63c5e2;

	padding: 2px 10px 2px 10px;
	margin: 0px 0px 100px 0px;

	font-family: 'Avenir Next', Helvetica, sans-serif;
	font-size: 10px;
	font-weight: normal;
	color: white;

	box-shadow: 0px 2px 1px #888888, -2px 2px 1px #888888;
	box-sizing: initial;
}
&#13;
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<div id="volleyDiv" style="display: block;">
  <div class="volleyThreadDiv" id="volleyThreadDivUAuCOyQuav" style="display: block;">
    <div class="volleyComment" id="volleyCommentUAuCOyQuav">
      <p class="volleyCommentDate">Feb 28th</p>
      <p class="volleyCommentStatus">First comment!</p>
      <p class="volleyCommentAuthor">John Wexler</p>
    </div>
    <div class="volleyReply" id="volleyReply0wblbTaP1R">
      <p class="volleyReplyDate">Feb 28th</p>
      <p class="volleyReplyStatus">First comment!</p>
      <p class="volleyReplyAuthor">John Wexler</p>
    </div>
    <div class="volleyReply" id="volleyReplywBS0WFoUDH">
      <p class="volleyReplyDate">Feb 28th</p>
      <p class="volleyReplyStatus">Testing two comments on a a page.</p>
      <p class="volleyReplyAuthor">John Wexler</p>
    </div>
    <div class="volleyReply" id="volleyReply5zw2ww9GBo">
      <p class="volleyReplyDate">Feb 28th</p>
      <p class="volleyReplyStatus">Will it blend?</p>
      <p class="volleyReplyAuthor">John Wexler</p>
    </div>
    <div class="volleyReply" id="volleyReplythWrBLrkjy">
      <p class="volleyReplyDate">Feb 28th</p>
      <p class="volleyReplyStatus">Stay with me.</p>
      <p class="volleyReplyAuthor">John Wexler</p>
    </div>
    <div class="volleyCommentReply" id="volleyCommentReplyUAuCOyQuav">Reply</div>
  </div>
</div>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我找到的解决方案是在.volleyCommentStatus,.volleyReplyStatus的css中添加 position:relative

它似乎是继承位置:静态,我认为是导致视网膜屏幕问题。