2013-06-19 4 views
0

내 웹 사이트 (www.arrow-tvseries.com)에서 스크롤 기능을 구현하려고합니다.스크롤 위로 HTML 웹 사이트의 JavaScript

"버튼"은 웹 사이트에 표시되지만 클릭하면 페이지 상단으로 스크롤되지 않기 때문에 제대로 작동하지 않습니다. 더 이상 나는 페이지의 절반을 말하면서 아래로 스크롤 될 때 "스크롤 가기 버튼"이 보이기를 원합니다. 여기

는 자바 스크립트 코드 :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"   type="text/javascript"></script> 

<script type="text/javascript"> 
$(function() { 
$(window).scroll(function() { 
    if($(this).scrollTop() != 200) { 
     $('#backtotop').fadeIn(); 
    } else { 
     $('#backtotop').fadeOut(); 
    } 
}); 

$('#backtotop').click(function() { 
    $('body,html').animate({scrollTop:0},800); 
}); 
}); 
</script> 

HTML 코드 (헤드 태그) :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"  "http://www.w3.org/TR/html4/frameset.dtd"> 

<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
<head> 
    <title>Arrow-TvSeries - Home</title> 

     <link rel="stylesheet" type="text/css" href="style.css"> 

    <!--back to top links--> 
     <link rel="stylesheet" type="text/css" href="back_to_top.css"> 
     <script src="/scripts/back_to_top.js" type="text/javascript"></script> 
    <!--end of back to top links--> 

    <meta property="fb:admins" content="{793705343}"/> 
    <!--Google Analytics--> 
    <script type="text/javascript"> 
     (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
     (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
     m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
     })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

     ga('create', 'UA-40124321-1', 'arrow-tvseries.com'); 
     ga('send', 'pageview'); 
    </script> 

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
    <meta name="description" content="Arrow Tv Show"> 
    <meta name="keywords" content="arrow, tv show, amel, stephen amell, katie cassidy, oliver, oliver queen, queen"> 
    <meta name="author" content="Ståle Refsnes"> 
    <meta charset="UTF-8"> 

    <!--IPAD setting--> 
    <meta name="viewport" content="width = 730, initial-scale=0.70, minimum-scale = 0.5, maximum-scale = 1.25"/> 
</head>  

CSS 코드 :

#backtotop { 
cursor : pointer; 
/*display : none;*/ 
margin : 0px 0px 0px 370px; 
position : fixed; 
bottom : 10px; 
font-size : 90%; 
padding : 10px; 
width : 100px; 
text-align : center; 
background-color : #000; 
border-radius : 8px; 
-webkit-border-radius : 8px; 
-moz-border-radius : 8px; 
filter: alpha(opacity=60); 
-khtml-opacity : 0.6; 
-moz-opacity : 0.6; 
opacity : 0.6; 
color : #FFF; 
font-size : 14px; 
z-index : 10000; 
font-family: arial; 
} 

#backtotop:hover { 
filter : alpha(opacity=90); 
-khtml-opacity : 0.9; 
-moz-opacity : 0.9; 
opacity : 0.9; 
} 

주시기 및 알려 주시기 바랍니다 당신이 경우 추가 코드 또는 정보가 필요합니다.

감사

+0

코드 시체? –

+0

이 질문에 대한 답변은 도움이 될 수 있습니다. http://stackoverflow.com/questions/17043145/static-and-sticky-fixed-header-transition-misfunction/17043288#17043288 – cfs

+0

또한 몇 가지 구문 오류가 있습니다 귀하의 사이트에서'Firebug (Firefox)'의'Console' 탭이나 Google Chrome의'Developer Tools' - F12 –

답변

2

이 시도하고 알려 :

<!DOCTYPE html> 
<html> 
    <head> 
     <style> 
      input.pos_fixed 
      { 
       position:fixed; 
       top:30px; 
       right:5px; 
      } 
     </style> 

     <script> 
      function scrollWindow() 
      { 
       window.scrollTo(0,0); 
      } 
     </script> 
    </head> 

    <body> 
     <br> 
      <input class="pos_fixed" type="button" onclick="scrollWindow()" value="Scroll" /> 
     <br> 
    </body> 
</html> 
0

아래 코드와 같은 일을 수행 할 수 있습니다

$("a[href='#top']").click(function() { 
    $("html, body").animate({ scrollTop: 0 }, "slow"); 
    return false; 
}); 

이보십시오. 희망이 도움이됩니다.

0

은 당신이 뭔가를 할 수 있습니다 :

JSFiddle demo

$(window).scroll(function() { 

    // if you have scrolled down more than 200px 
    if($(this).scrollTop() > 200) { 
     $('#backtotop').fadeIn(); 
    } else { 
     $('#backtotop').fadeOut(); 
    } 
}); 



$('#backtotop').bind('click', function(e) { 
    e.preventDefault(); 
    $('body,html').animate({scrollTop:0},800); 
}); 
0

문제는 당신의 자바 스크립트 파일이 실제로 HTML로 작성된 것입니다. 당신의 HTML head 섹션에서

, 당신은이 있어야합니다

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> 
<script src="scripts/back_to_top.js" type="text/javascript"></script> 

를 그런 다음 back_to_top.js 다음 를 포함해야합니다 : 그것은 작동하지 않는 경우

$(function() { 
    $(window).scroll(function() { 
     if($(this).scrollTop() != 200) { 
      $('#backtotop').fadeIn(); 
     } else { 
      $('#backtotop').fadeOut(); 
     } 
    }); 

    $('#backtotop').click(function() { 
     $('body,html').animate({scrollTop:0},800); 
    }); 
}); 
+0

잘 했어 !! 그 지금 일하고있어. 대단히 감사합니다! –