arkarna,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.hot{
border: 1px dashed Gray; padding: 5px; height: 100px; width: 100px ;
background-color: rgba(139, 69, 19, 1);
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function() {
$.fn.Timer = function Timer(obj) {
var def = {
from: 5E3,
duration: 5E3,
to: 0,
callback: null,
step: function(now, fx) {
fx.elem.setAttribute("style", "margin-left:"+(now | 0)+"px !important");
}
};
var opt = $.extend({}, def, obj);
return this.each(function(indx, el) {
$(el).queue(function() {
el.n = opt.from;
$(el).dequeue()
});
$(el).animate({
n: opt.to
}, {
easing: "swing",
duration: opt.duration,
step: opt.step,
complete: opt.callback
})
})
};
$(window).on("resize", function() {
var obj = {from: 0,
duration: 300,
to: 250};
if ($(window).width() < 800) obj = {from: 250,
duration: 300,
to: 0};
$(".hot").stop().Timer(obj);
}).resize()
});
</script>
</head>
<body>
<div class="hot"></div>
</body>
</html>