Всегда Активный первый элемент страницы
Здравствуйте. Помогите решить задачу.
В jquery не разбираюсь, нужно чтобы первый элемент на странице был по умолчанию открыт. http://new1.grkmask.ru Подскажите, пожалуйста, что нужно изменить/добавить?
<script>
jQuery(document).ready(function($) {
if (jQuery(window).width() > 1024) {
base_width = $('.strip-menu').attr('data-width');
count = $('.strip-menu').attr('data-count');
$('section.strip-item').hover(function(){
$('.strip-item').css('width', (100-base_width*2)/(count-1)+'%');
$(this).css('width', base_width*2+'%');
},function(){
$('.strip-item').css('width', base_width+'%');
});
}
if (jQuery(window).width() > 760 && jQuery(window).width() < 1025) {
jQuery('.wrapped_link').click(function(e) {
if (!jQuery(this).parents('.strip-item').hasClass('hovered')) {
base_width = $('.strip-menu').attr('data-width');
count = $('.strip-menu').attr('data-count');
e.preventDefault();
jQuery('.strip-item').removeClass('hovered');
jQuery(this).parents('.strip-item').addClass('hovered');
jQuery('.strip-item').css('width', (100-base_width*2)/(count-1)+'%');
jQuery(this).parents('.strip-item').css('width', base_width*2+'%');
}
});
}
});
</script>
|
Цитата:
Только содержимое первого элемента не отображается (лого, текст) И когда убираешь мышку с окна, первый элемент снова закрывается. |
New2017,
jQuery(document).ready(function($) {
if (jQuery(window).width() > 1024) {
var show = function(index) {
items.css("width", (100 - base_width * 2) / (count - 1) + "%").eq(index).css("width", base_width * 2 + "%")
};
base_width = $(".strip-menu").attr("data-width");
count = $(".strip-menu").attr("data-count");
var items = $("section.strip-item").hover(function() {
show(items.index(this))
}, function() {
show(0)
});
show(0)
}
if (jQuery(window).width() > 760 && jQuery(window).width() < 1025) jQuery(".wrapped_link").click(function(e) {
if (!jQuery(this).parents(".strip-item").hasClass("hovered")) {
base_width =
$(".strip-menu").attr("data-width");
count = $(".strip-menu").attr("data-count");
e.preventDefault();
jQuery(".strip-item").removeClass("hovered");
jQuery(this).parents(".strip-item").addClass("hovered");
jQuery(".strip-item").css("width", (100 - base_width * 2) / (count - 1) + "%");
jQuery(this).parents(".strip-item").css("width", base_width * 2 + "%")
}
})
});
|
рони,
Супер, спасибо. Еще бы добавить отображение лого и текста на первом элементе |
New2017,
jQuery(document).ready(function($) {
var items = $("section.strip-item").hover(function() {
show(items.index(this))
}, function() {
show(0)
}),
base_width = $(".strip-menu").attr("data-width"),
count = $(".strip-menu").attr("data-count");
function show(index) {
items.css("width", (100 - base_width * 2) / (count - 1) + "%")
.removeClass("hovered")
.eq(index).css("width", base_width * 2 + "%")
.addClass("hovered")
}
show(0)
});
|
| Часовой пояс GMT +3, время: 09:06. |