티스토리 뷰
[ JavaScript ] 창 외부 베너 스크롤시 따라다니는 베너 - scroll banner
MiniNeko 2015. 11. 29. 05:06// CSS
/* DIV SIDE BANNER 시작 */
#divLeftBanner{left:50%; width:100px; margin-left:-610px; z-index:9999px;}
#divRightBanner{right:50%; width:100px; margin-right:-610px; z-index:9999px;}
/* DIV SIDE BANNER 시작 */
==========================================================================================
// SCRIPT
$(document).ready(function () {
$(window).scroll(function () {
var positionTop = 0;
var scrollHeight = $(window).scrollTop();
//alert("scrollHeight : "+ scrollHeight); // 2583
//var windowHeight = $(window).height();
//alert("windowHeight : "+ windowHeight); // 909
//var documentHeight = $(document).height();
//alert("documentHeight : "+ documentHeight); // 3492
if( scrollHeight >= 230 ) {
//alert("1");
//alert("window.height : "+ scrollHeight + " window.scrollTop : " + windowHeight + " / documentHeight : "+documentHeight);
//alert( $("#divRightBanner").position().top );
$("#divLeftBanner").css('position','fixed').css('top','10px');
$("#divRightBanner").css('position','fixed').css('top','10px');
} else {
//alert("2");
positionTop = 230 - scrollHeight;
if( scrollHeight == 0 ) {
$("#divLeftBanner").css('position','fixed').css('top','230px');
$("#divRightBanner").css('position','fixed').css('top','230px');
} else {
$("#divLeftBanner").css('position','fixed').css('top',positionTop+'px');
$("#divRightBanner").css('position','fixed').css('top',positionTop+'px');
}
}
});
});
==========================================================================================
// HTML
< div id="divRightBanner" align="left" style=" position:fixed; top:230px; width:100px; border:0px solid #DDD;">
< img src="/img/pages/imgRightBanner.jpg" width="100" />
< SCRIPT language="JavaScript">
function pageChangeRightHandler(strMid) {
document.location.href='/pages/business/?txtMid='+strMid;
}
< /SCRIPT>
< ?
// 이미지 정보
$query = "SELECT * FROM BANNER WHERE GUBUN = '2' ORDER BY RANK ASC ";
$result = mysql_query($query);
$rowNum = mysql_affected_rows();
for($i = 0; $i < $rowNum; $i++) {
$row = mysql_fetch_array($result);
if($row[FILENAME]!="") {
$row[FILENAME] = fileViewHandler($row[FILENAME]); // miniHandler
if($row[LINK]!="") {
echo "<img src='/CMS/banner/img/".$row[FILENAME]."' style='border:1px solid #DDD; cursor:pointer;' onClick='pageChangeRightHandler("".$row[LINK]."")'/><br />";
} else {
echo "<img src='/CMS/banner/img/".$row[FILENAME]."' style='border:1px solid #DDD;'/><br />";
}
}
}
?>
< table width="100" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #ddd; margin:5px 0px;"><tr><td align="center" style="font-weight:bold; padding:3px;">
< a href="#">TOP</a>
< /td></tr></table>
< /div>
'Language > JavaScript' 카테고리의 다른 글
[ JavaScript ] 화면크기 확대축소, 늘이기 줄이기 (0) | 2015.11.29 |
---|---|
[ JavaScript_JS ] 단축키 지정 - Shortcuts (0) | 2015.11.29 |
[ JavaScript ] scroll - 스크롤 이벤트 - 스크롤이 하단에 닫으면 실행 (0) | 2015.11.29 |
[ JavaScript ] 스크롤 베너 (0) | 2015.11.29 |
[ JavaScript ] 날자 구하기 (0) | 2015.11.29 |