I created some "3-D stack div" based on some jquery plugin.
Basically, each div has its own id, and the active div will has an attribute data-position="1"
while other unactive div will has data-position="2"
or data-position="3"
.
Now, how can I make an if else statement using jquery where if that div id data-position="1"
, it will do something specific. For learning purpose, let's just make different div id will show a different custom alert text.
P/S : I found this solution Jquery data attribute value equals, but the thing is it target the same class name which not the same with my case.
EDIT : I add a new jquery where if this div id has this data-class value
, show an alert. It works fine, but if I change to if this div id has this data-position value
, nothing happen. Why is that?
This is the code where it won't work
jQuery(".next").on('click', function() {
if ($("#discover").data("position") == '1') {
alert("Help Me");
}
});
$( "#slider" ).stack_slider({
autoPlaySpeed: 6000,
autoPlay: false,
dots: false,
arrows: false,
drag: false,
direction: "vertical"
});
jQuery(".next").on('click', function() {
if ($("#discover").data("class") == '1') {
alert("Help Me");
}
});
.dp-wrap {
margin: 0 auto;
position: relative;
perspective: 1000px;
height: 100%;
}
.dp_item {
position: absolute;
transition: transform 1.2s;
border: 1px solid #707070;
}
#slider {
position: relative;
}
#dp-slider .dp_item:first-child {
z-index: 10 !important;
transform: rotateY(0deg) translateX(0px) !important;
background: #fff;
}
.dp_item[data-position="2"] {
z-index: 9;
transform: rotateY(0deg) translateX(10%) scale(0.9);
}
.dp_item[data-position="3"] {
z-index: 8;
transform: rotateY(0deg) translateX(20%) scale(0.8);
}
#dp-slider {
height: auto;
min-height: 600px;
}
#dp-slider .dp_item:hover:not(:first-child) {
cursor: pointer;
}
/* vertical layout */
.vertical #dp-slider .dp_item[data-position="3"] {
transform: rotateY(0deg) translateY(-3%) scale(0.8);
}
.vertical #dp-slider .dp_item[data-position="2"] {
transform: rotateY(0deg) translateY(9%) scale(0.9);
}
.vertical #dp-slider .dp_item:first-child {
transform: rotateY(0deg) translateY(calc(21% - .5px)) scale(1) !important;
}
.vertical #dp-slider .dp_item[data-position="2"] img,
.vertical #dp-slider .dp_item[data-position="3"] img {
-webkit-filter: blur(1px); /* Safari 6.0 - 9.0 */
filter: blur(1px);
}
.dp-text {
padding: 20px;
}
.dp-text h5 {
color: #404040;
}
.dp-text h5 span {
border: 2px solid #404040;
border-radius: 50%;
padding: 1% 3%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://iceiceicy.com/causeeffect/wp-includes/js/stack-slider.js"></script>
<div id="slider">
<div class="dp-wrap">
<p class="next" style="color: #000; cursor: pointer;">NEXT</p>
<div id="dp-slider">
<div id="discover" class="dp_item" data-class="1" data-position="1">
<div class="dp-img">
<img src="https://causeeffect.asia/wp-content/uploads/2018/12/fsbolt.png" />
</div>
<div class="dp-text">
<h5><span>1</span> DISCOVER</h5>
</div>
</div>
<div id="define" class="dp_item" data-class="2" data-position="2">
<div class="dp-img">
<img src="https://causeeffect.asia/wp-content/uploads/2018/12/fsbolt.png" />
</div>
<div class="dp-text">
<h5><span>2</span> DEFINE</h5>
</div>
</div>
<div id="develop" class="dp_item" data-class="3" data-position="3">
<div class="dp-img">
<img src="https://causeeffect.asia/wp-content/uploads/2018/12/fsbolt.png" />
</div>
<div class="dp-text">
<h5><span>3</span> DEVELOP</h5>
</div>
</div>
</div>
</div>
</div>