isInvalid: function(input) {
return /@(gmail|yahoo)\.[a-z]+$/.test(input.value.trim().toLowerCase());
}
function recountItem(el_summ, el_quantity, n_price, e) {
action = e ? e.target.className.match(/\w+_+(\w+)/)[1] : '';
n_quantity = parseInt(el_quantity.text());
switch(action){
case 'plus':
case 'increment':
n_quantity ++;
break;
case 'minus':
case 'decrement':
n_quantity = n_quantity > 1 ? n_quantity - 1 : n_quantity;
break;
}
el_quantity.text(n_quantity);
el_summ.text(n_quantity * n_price + ' грн.');
};
//order
$('.order__block').each(function() {
var $e = $(this),
el_quantity = $e.find('.order__value'),
el_summ = $e.find('.order__sum'),
n_price = $e.find('.order__value').attr('data-number');
$e.find('.order__plus').click(function(e) {
recountItem(el_summ, el_quantity, n_price, e)
});
$e.find('.order__minus').click(function(e) {
recountItem(el_summ, el_quantity, n_price, e)
});
recountItem(el_summ, el_quantity, n_price);
});
//single
$('.single__row').each(function() {
var $e = $(this),
el_quantity = $e.find('.single__count'),
el_summ = $e.find('.single__price'),
n_price = $e.find('.single__count').attr('data-price');
$e.find('.single__increment').click(function(e) {
recountItem(el_summ, el_quantity, n_price, e)
});
$e.find('.single__decrement').click(function(e) {
recountItem(el_summ, el_quantity, n_price, e)
});
recountItem(el_summ, el_quantity, n_price);
});
//basket
$('.basket__item').each(function() {
var $e = $(this),
el_quantity = $e.find('.basket__value> span'),
el_summ = $e.find('.basket__sum'),
n_price = $e.find('.basket__single').text();
$e.find('.single__increment').click(function(e) {
recountItem(el_summ, el_quantity, n_price, e);
updateBasketTotalSum();
});
$e.find('.single__decrement').click(function(e) {
recountItem(el_summ, el_quantity, n_price, e);
updateBasketTotalSum();
});
recountItem(el_summ, el_quantity, n_price);
updateBasketTotalSum();
});
function updateBasketTotalSum() {
var sum = 0;
$('.basket__sum').each(function() {
sum += parseInt($(this).text());
});
$('.basket__count').text(sum + ' грн.');
}
$('.basket__close').on('click', function() {
$(this).parent().parent().remove();
});
document.querySelectorAll("button").forEach(el => el.addEventListener("mouseover", e => alert("Вы навели на кнопку: "+e.target.textContent)))
{
"name": "My extension",
...
"content_scripts": [
{
"matches": ["http://*.nytimes.com/*"],
"css": ["myStyles.css"],
"js": ["contentScript.js"]
}
],
...
}
$(function(){
$("button").click(function(){
var lastInput = $('input[type="datetime-local"]:last');
var type = lastInput.attr("type");
var min = lastInput.attr("min") == undefined ? "" : lastInput.attr("min");
var name = lastInput.attr("name");
var num = parseInt(name.replace("date",""));
if (num < 20) {
$("#container").append('<input type="'+type+'" min="'+min+'" name="date'+(num+1)+'"/>');
}
if (num >= 19) {
$("button").hide();
}
})
})
document.querySelector("button").addEventListener("click", e => {
const items = document.querySelectorAll(".item");
const first = items[0].textContent;
[...items].map((el, i) => {
el.textContent = (i < items.length - 1) ? items[i+1].textContent : first;
});
})
Но когда показывается последний элемент, то смена контента должна прекратиться, аналогично и с первым.
document.querySelector(".works__more__btn").addEventListener("click", function() {
var elem = document.createElement("div");
elem.setAttribute("class", "works__content__smallRow");
elem.innerHTML = `
<img src="https://www.placehold.it/375x327/25" class="works__content__smallRow__item">
<img src="https://www.placehold.it/375x327/50" class="works__content__smallRow__item">
<img src="https://www.placehold.it/375x327/75" class="works__content__smallRow__item">
<img src="https://www.placehold.it/375x327/100" class="works__content__smallRow__item">
`;
document.querySelector(".works__content").appendChild(elem);
document.querySelector(".works__more").style.display = "none";
});
document.querySelector(".works__more__btn").addEventListener("click", function() {
document.querySelector(".works__content").appendChild(document.querySelector(".works__content").cloneNode(true));
document.querySelector(".works__more").style.display = "none";
});
if ($('#name').val().length >= 3) {
$(this).find('#name').css("border", "1px solid rgb(169, 169, 169)");
} else if ($('#email').val().length > 10 && $('#email').val().search(pattern) == 0) {
$(this).find('#email').css("border", "1px solid rgb(169, 169, 169)");
}
if ($('#name').val().length >= 3) {
$(this).find('#name').css("border", "1px solid rgb(169, 169, 169)");
}
if ($('#email').val().length > 10 && $('#email').val().search(pattern) == 0) {
$(this).find('#email').css("border", "1px solid rgb(169, 169, 169)");
}
document.location.href += "&" + document.referrer
.split("?")[1]
.split("#")[0]
.split("&")
.filter(str => str.indexOf("utm_") > -1)
.join("&");
document.location.href += document.referrer.indexOf("?") > -1 ?
"&" + document.referrer
.split("?")[1]
.split("#")[0]
.split("&")
.filter(str => str.indexOf("utm_") > -1)
.join("&") : "";
var checker = {
// получить координаты углов объекта
getRectangle: function (el) {
return {
left: el.offsetLeft,
top: el.offsetTop,
right: el.offsetLeft + el.offsetWidth,
bottom: el.offsetTop + el.offsetHeight
}
},
// проверка на пересечение
collide: function (el1, el2) {
var rect1 = this.getRectangle(el1);
var rect2 = this.getRectangle(el2);
return !(
rect1.top > rect2.bottom ||
rect1.right < rect2.left ||
rect1.bottom < rect2.top ||
rect1.left > rect2.right
);
},
// проверка на совпадение
inside: function (el1, el2) {
var rect1 = this.getRectangle(el1);
var rect2 = this.getRectangle(el2);
return (
((rect2.top <= rect1.top) && (rect1.top <= rect2.bottom)) &&
((rect2.top <= rect1.bottom) && (rect1.bottom <= rect2.bottom)) &&
((rect2.left <= rect1.left) && (rect1.left <= rect2.right)) &&
((rect2.left <= rect1.right) && (rect1.right <= rect2.right))
);
}
}
jQuery(".sp-body.folded").hide();
jQuery(".sp-head").each(function(){
$this = jQuery(this);
$this.addClass("unfolded");
$this.next().slideDown("fast");
$this.next().removeClass("folded");
$this.prop('title', title.folded);
});
var isUnfolded = false;
function toggleSpoilers() {
jQuery(".sp-head").each(function(){
$this = jQuery(this);
if(isUnfolded) {
$this.removeClass("unfolded");
$this.next().slideUp("fast");
$this.next().addClass("folded");
$this.prop('title', title.unfolded);
} else {
$this.addClass("unfolded");
$this.next().slideDown("fast");
$this.next().removeClass("folded");
$this.prop('title', title.folded);
}
});
isUnfolded = !isUnfolded;
}
body {
background: red;
padding: 20px;
font-family: Helvetica;
}
.text {
margin-bottom : 15%;
transition: all 1s;
}
.knopka {
opacity: 0;
transition: all 1s;
}
$(".kvadrat").mouseenter(function(){
$(".knopka").css({
'opacity' : '1'
});
$(".text").css({
'margin-bottom' : '30%'
});
});
$(".kvadrat").mouseleave(function(){
$(".knopka").css({
'opacity' : '0',
});
$(".text").css({
'margin-bottom' : '15%'
});
});