jQueryの内部でPHPコードを使用して同じページをスムーズにスクロールしようとしています(PHPを使用して最終的なjqueryコードを生成しようとしています)。しかし、それは働いていない何らかの理由で、誰もが誤りを指摘することができれば、私は感謝したり、それが同じページのスムーズスクロールが機能しない
// When the Document Object Model is ready
jQuery(document).ready(function(){
// 'scroll' is the amount of pixels destination
// is from the top of the document
var scroll = jQuery('<?php echo get_option('smooth_scroll'); ?>').offset().top;
// When button is clicked
jQuery('.test').click(function(){
// Scroll down to 'scroll'
jQuery('html, body').animate({scrollTop:scroll}, 'slow');
// Stop the link from acting like a normal anchor link
return false;
});
});
を働いていない、なぜ私はそれでクラス「テスト」とhrefのリンクを持っています。そのボタンをクリックすると、同じページの特定のdivにスクロールするためのスムーズなスクロールが必要になります。[get_option( 'smooth_scroll')] divはユーザーによって更新されます)。
一般的に言えば、JavascriptやjQueryの中にPHPをテンプレート化するのは避けるべきですが、それは意見です。ただし、誰でもあなたの問題を解決できるようにするには、get_option( 'smooth_scroll')の出力値を指定する必要があります。また、ブラウザのコンソールを見て、そこにある可能性のあるエラーを追加する必要があります。 – rdgd
"scrolltop.js:82 Uncaught SyntaxError:missing"引数リストの後 "error on" .offset()。top; " line –