Я хочу получить img по свойству css, на jQuery. свойство margin-left: -1920px.Как получить img своим свойством css jQuery
Как я могу это сделать?
Я пробовал $('img').css('margin-left', '-1920px'); console.log('img');
, но, конечно, его изменение собственности и этого я не хочу. Я хочу сначала получить элемент, а затем изменить свойство. Как я могу получить элемент?
мой JQuery код:
$(document).ready(function() {
var sliderUL = $('.slider').children('ul'),
imgs = sliderUL.find('img'),
imgWidth = imgs[0].width, // 960
imgsLen = imgs.length, // 4
current = 1,
totalImgsWidth = imgsLen * imgWidth;
$('#slider-nav')
.show().find('button').on('click', function() {
direction = $(this).data('dir');
var loc = imgWidth;
(direction === 'next') ? ++current : --current;
if (current === 0) {
current = imgsLen;
direction = 'next';
loc = totalImgsWidth - imgWidth;
} else if (current - 1 === imgsLen) {
current = 1;
loc = 0;
}
transition(sliderUL, loc, direction);
});
function transition(container, loc, direction) {
var unit;
if (direction && loc !== 0) {
unit = (direction === 'next') ? '-=' : '+=';
}
container.animate({
'margin-left': unit ? (unit+loc) : loc
})
}
});
мой HTML:
<body>
<div id="slider-nav">
<button data-dir="prev"><</button>
<button data-dir="next">></button>
</div>
<div class="slider">
<ul>
<li><img src="img1.jpg" alt="image"></li>
<li><img src="img2.jpg" alt="image"></li>
<li><img src="img3.jpg" alt="image"></li>
<li><img src="img4.jpg" alt="image"></li>
</ul>
</div>
Не работает. Я не понимаю, почему. Это часть моего кода:.. '\t $ ('# слайдер нав') \t \t .show() найти ('кнопка') на ('нажмите', функция() { \t \t \t направление = $ (это) .data ('реж'); \t \t \t \t вар LOC = imgWidth; \t \t \t (направление === 'следующая')?++ current: --current; \t \t \t \t \t \t, если (текущий === 0) { \t \t \t \t ток = imgsLen; \t \t \t \t direction = 'next'; \t \t \t \t loc = totalImgsWidth - imgWidth; \t \t \t}); \t \t \t \t} иначе, если (ток - 1 === imgsLen) { \t \t \t \t ток = 1; \t \t \t \t loc = 0; \t \t \t} \t \t}); ' Я хочу, чтобы получить IMG, что в забаве на-звоном находится в MarginLeft: 1920px. Как я могу это сделать и где его написать в коде? –