var maxTime = 1000,
maxDistance = 50,
target = $('#box'),
startX = 0,
startTime = 0,
touch = "ontouchend" in document,
startEvent = (touch) ? 'touchstart' : 'mousedown',
moveEvent = (touch) ? 'touchmove' : 'mousemove',
endEvent = (touch) ? 'touchend' : 'mouseup';
target.bind(startEvent, function(e) {
startTime = e.timeStamp;
startX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX;
}).bind(endEvent, function(e) {
startTime = 0;
startX = 0;
}).bind(moveEvent, function(e) {
var currentX = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
currentDistance = (startX === 0) ? 0 : Math.abs(currentX - startX),
currentTime = e.timeStamp;
if (startTime !== 0 && currentTime - startTime < maxTime && currentDistance > maxDistance) {
if (currentX < startX) {
target.find('h1').html('Swipe Left').fadeIn();
setTimeout(function() {
target.find('h1').fadeOut();
}, 1000);
}
if (currentX > startX) {
target.find('h1').html('Swipe Right').fadeIn();
setTimeout(function() {
target.find('h1').fadeOut();
}, 1000);
}
startTime = 0;
startX = 0;
}
});
h1 {
text-align: center;
font-size: 24px;
}
#box {
width: 800px;
height: 600px;
margin: 30px auto;
background-color:#eee;
}
#left{ position:relative; float:left; width:40%;
}
#right{ position:relative; float:left; width:40%; }
#right .iframe_cover{
position: absolute;
width: 100%;
height: 40%;
top: 0;
left: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h1>Swipe Inside the Box</h1>
<div id="box">
<div id="left">
<h1></h1>
<p> this is some text</p>
</div>
<div id="right">
<iframe src="https://lnt.org/" frameborder="0" height="430"></iframe>
<div class="iframe_cover"></div>
</div>
</div>