добавить в скрипт приоритет к стилю
Есть такой скрипт:
if ($(window).width() < 800) {
$('div.какой-то див').animate({
marginLeft: -250 * direction
}, 300)
надо дописать! important чтобы выглядело marginLeft: -250!important * direction (но конкретно так я сделать не могу, нужен рабочий вариант) в обычном css это выглядело бы так: margin-left: -250px! important; |
arkarna,
изменить строку 24 по ссылке https://javascript.ru/forum/misc/708...tml#post466811 |
Можно поконкретнее, что на что менять?
|
jquery animate css !important
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>
|
так,получается,с помощью elem.setAttribute я смогу добавить в стили к маргинлефту параметр !important?
|
arkarna,
:-? |
| Часовой пояс GMT +3, время: 12:29. |