PHP & JavaScript Room :: 設置サンプル

実行結果

設置サンプル

参照: Smart Floating Banners

▼画面をスクロールしても、常に定位置にバナーが表示されます。

 some content

設置サンプルのソース

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="ja" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="Content-Style-Type" content="text/css" />
      <meta http-equiv="imagetoolbar" content="no" />
       <title>設置サンプル</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <!-- JS -->
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript">
         $(function(){
            $(window).scroll(function(){
               if($(window).scrollTop() > $(".smartBannerIdentifier").offset({ scroll: false }).top){
                  $(".banner").css("position", "fixed");
                  $(".banner").css("top", "0");
               }
               if($(window).scrollTop() <= $(".smartBannerIdentifier").offset({ scroll: false }).top){
                  $(".banner").css("position", "relative");
                  $(".banner").css("top", $(".smartBannerIdentifier").offset);
               }
            }); 
         });
      </script>
      <!-- CSS -->
      <style type="text/css">
         .main { width:750px; margin:0 auto; }
         .cleft  { float:left; width:500px; background-color:#ccc; }
         .cright { float:right; width:250px; background-color:#63b6ce; color:#fff; }
         .banner { background-color:#effff7; width:250px; }
         .inner { margin:10px; }
      </style>
   <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
   <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP &amp; JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
      <div id="wrap">
         <h1>設置サンプル</h1>
         <p>参照: <a href='http://www.webresourcesdepot.com/smart-floating-banners/'>Smart Floating Banners</a></p>
         <p>▼画面をスクロールしても、常に定位置にバナーが表示されます。</p>
<!-- CODE -->
         <div class="main cf">
            <div class="cleft">
               <div class="inner">
                  <script type="text/javascript">
                     for(var i=0; i<=20; i++){
                        document.write("some content<br \/><br \/><br \/><br \/><br \/><br \/>\n");
                     }
                  </script>
               </div>
            </div><!-- cleft -->
            <div class="cright">
               <p style="margin:50px 0;"> some content</p>
               <div class="smartBannerIdentifier"></div>
               <div class="banner">
                  <!-- バナー -->
                  <script type="text/javascript" src="http://widgetserver.com/syndication/subscriber/InsertWidget.js?appId=f5909429-d5b3-4c5c-befb-da918501d20b"></script><noscript>Get the <a href="http://www.widgetbox.com/widget/bunnyhero-penguin">bunnyhero penguin</a> widget and many other <a href="http://www.widgetbox.com/">great free widgets</a> at <a href="http://www.widgetbox.com">Widgetbox</a>!</noscript>
               </div><!-- banner -->
               </div>
            </div><!-- cright -->
         </div>
<!-- CODE / -->
      </div>
   </body>
</html>