私はiWebを使用しています(恐ろしいですが、私は長い話をしています)。iWeb iFrameとスムーズなスクロールの問題
私はページ上で滑らかなスクロールリンクを得ることができましたが、正しい位置にスクロールすることができません。ここで
はインラインフレームにロードされ、「HTMLウィジェット」(FYIこれはメニューである)のために私のコードです:
<html>
<head>
<script type="text/javascript">
// the var's are referneces to iWeb's generated div's have to publish and get id's
var about = "id1";
var products = "id4";
var technical = "id7";
// var contactus = "id14";
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body', window.parent.document).animate({
//scrollTop: parent.document.getElementById(products).offsetTop // this works but is a static ref
scrollTop: parent.document.getElementById(theTarget).offsetTop
}, 1000);
return false;
}
}
});
});
</script>
</head>
<body>
<div style="width: "100%"; height: "0%"">
<a href="#about" id="about" class="myButton">About</a>
<a href="#products" id="products" class="myButton">Products</a>
<a href="#technical" id="technical" class="myButton">Technical</a>
<a href="#contactus" id="contactus" class="myButton">Contact</a>
</div>
</body>
</html>
私はリンク上でこのクリックを表示したときに今、それだけでロードされますメインウィンドウをスクロールせずにiframeページを表示します。
しかし、他のScrollTop行のコメント/コメントを外しても機能するが、明らかに親ウィンドウの "id4" divにスクロールするだけだ。
どうすればこの機能を、リンクごとに同じ機能を何度もコピーしたり貼り付けたりせずに済ませることができますか?