矢印をクリックするとスライダを左右に移動する機能を記述しました。スライダは、URLのハッシュを変更することによって機能します。jQuery on click only once
機能:
var navigateGalleryForward = function() {
var pathName = window.location.href;
if (pathName.indexOf("item-1") != -1) {
window.location.hash = "item-2";
} else if (pathName.indexOf("item-2") != -1) {
window.location.hash = "item-3";
} else if (pathName.indexOf("item-3") != -1) {
window.location.hash = "item-1";
} else {
console.log("Something went wrong navigating the gallary..")
}
};
var navigateGalleryBackward = function() {
var pathName = window.location.href;
if (pathName.indexOf("item-1") != -1) {
window.location.hash = "item-3";
} else if (pathName.indexOf("item-2") != -1) {
window.location.hash = "item-1";
} else if (pathName.indexOf("item-3") != -1) {
window.location.hash = "item-2";
} else {
console.log("Something went wrong navigating the gallary..")
}
};
$(document).ready(function() {
$("#left-arrow").on('click', function() {
console.log("I work");
navigateGalleryBackward();
});
$("#right-arrow").on('click', function() {
console.log('work');
navigateGalleryForward();
});
});
アローズ例:
<figure class="item one">
<img onClick="navigateGalleryBackward" id="left-arrow" src="{{ 'arrow-left.png' | asset_url }}" alt="left">
<img onclick="navigateGalleryForward" id="right-arrow"src="{{ 'arrow-right.png' | asset_url }}" alt="right">
<h1 style="color: white; font-weight:bold; font-size: 2rem; margin-top:2em; ">5 New Sensors for Control4</h1>
<p style="color: white; font-size:1.2rem;">Learn more about Dome's new line of cross-compatible sensors.</p>
<img style="height: 150px; margin-top: 3em; margin-right: 3em;"class="figure_h" src="{{ 'slide_show_1.jpg' | asset_url }}" />
<button style="margin-top: 3em; display:block; margin: auto;" class="btn_k">BUY NOW</button>
</figure>
ので、図1に、それが動作します。しかし、数字2と3ではそうではありません。それが発砲した後、再び発射されません。
図2および3:
<figure class="item two">
<img onClick="navigateGalleryBackward" id="left-arrow" src="{{ 'arrow-left.png' | asset_url}}" alt="left">
<img onclick="navigateGalleryForward" id="right-arrow" src="{{ 'arrow-right.png' | asset_url }}" alt="right">
<h1 class="figure_h">2</h1>
</figure>
<figure class="item three">
<img onClick="navigateGalleryBackward" id="left-arrow" src="{{ 'arrow-left.png' | asset_url }}" alt="left">
<img onclick="navigateGalleryForward" id="right-arrow" src="{{ 'arrow-right.png' | asset_url }}" alt="right">
<h1 class="figure_h">3</h1>
</figure>
私はこの作業を取得するにはどうすればよい
?
ありがとうございました!