event.clientY - card.getBoundingClientRect().top
const card = document.querySelector('.container');
const cardItm = document.querySelector('.card');
const halfHeight = card.offsetHeight / 2;
const halfWidth = card.offsetHeight / 2;
card.addEventListener('mousemove', startRotate);
card.addEventListener('mouseout', stopRotate);
function startRotate() {
cardItm.style.transform = `rotateX(${-((event.clientY - card.getBoundingClientRect().top) - halfHeight) / 20}deg) rotateY(${((event.clientX - card.getBoundingClientRect().left) - halfWidth) / 20}deg)`;
};
function stopRotate(event) {
cardItm.style.transform = 'rotateX(0)';
};
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="light.css" class="style">
</head>
<body>
<button id="color">Сменить цвет</button>
<script type="text/javascript">
if (localStorage.getItem('style') == 'dark') {
document.querySelector('.style').href="dark.css";
}
document.querySelector('#color').onclick = function (){
if (document.querySelector('.style').getAttribute('href') === 'light.css') {
document.querySelector('.style').href="dark.css";
localStorage.setItem('style', 'dark');
} else {
document.querySelector('.style').href="light.css";
localStorage.setItem('style', 'light');
}
}
</script>
</body>
</html>
<style type="text/css">
body {
background: #fff;
color: #000;
}
#color {
color: #fff;
background: #000;
}
.dark {
background: #000;
color: #fff;
}
.dark #color {
color: #000;
background: #fff;
}
</style>
<button id="color">Сменить цвет</button>
<script type="text/javascript">
if (localStorage.getItem('style') == 'dark') {
document.body.classList.toggle('dark');
}
document.querySelector('#color').onclick = function (){
document.body.classList.toggle('dark');
if (document.body.getAttribute('class') == 'dark') {
localStorage.setItem('style', 'dark');
} else {
localStorage.setItem('style', '');
}
}
</script>
$db = new mysqli('localhost', 'root', 'root', 'basename'); //подключение к базе
$pageformat = '/test.php?page={pagenum}'; //Формат ссылки вместо {pagenum} будет номер страницы
$page = $_GET['page']; //Номер страницы
$num = 10; //Количество записей
$sql = "FROM `test`"; //sql запрос без SELECT
$result = Pagination ($db, $sql, $num, $pageformat, $page);
print_r($result['pagination']); //Ссылки на страницы
print_r($result['result']); //Контент в массиве
function Pagination ($db, $sql, $num, $pageformat, $page){
$result = $db->query("SELECT COUNT(*) ". $sql)->fetch_row();
$total = intval(($result[0] - 1) / $num) + 1;
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$getinfo = $db->query("SELECT * " .$sql. " LIMIT $start, $num");
$info = $getinfo->fetch_all(MYSQLI_ASSOC);
preg_match('/(?<a>.*?){pagenum}(?<b>.*?)/', $pageformat, $pg);
if ($page != 1) $pervpage = "<a href={$pg['a']}1{$pg['b']}><<</a><a href={$pg['a']}".($page - 1)." {$pg['b']}><</a>";
if ($page != $total) $nextpage = ' <a href='.$pg['a']. ($page + 1) .$pg['b'].'>></a><a href='.$pg['a'] .$total. $pg['b'].'>>></a>';
if($page - 2 > 0) $page2left = ' <a href='.$pg['a']. ($page - 2).$pg['b'].'>'. ($page - 2) .'</a> ';
if($page - 1 > 0) $page1left = '<a href='.$pg['a']. ($page - 1).$pg['b'].'>'. ($page - 1) .'</a> ';
if($page + 2 <= $total) $page2right = ' <a href='.$pg['a']. ($page + 2).$pg['b'] .'>'. ($page + 2).'</a>';
if($page + 1 <= $total) $page1right = ' <a href='.$pg['a']. ($page + 1).$pg['b'].'>'. ($page + 1).'</a>';
$pagination = $pervpage.$page2left.$page1left.'<a class="active" href="#">'.$page.'</a>'.$page1right.$page2right.$nextpage;
$result = array('pagination' => $pagination,'result' => $info);
return $result;
}
//Тут передаешь класс select
Select(document.querySelector('.beatu-select'));
if(currentBtn.classList.contains('active')){
currentBtn.classList.remove('active');
currentTub.classList.remove('active');
}
const tabsBtn = document.querySelectorAll(".tabs__nav-btn");
const tabsItems = document.querySelectorAll(".tabs__item");
tabsBtn.forEach(onTabClick);
function onTabClick(item) {
item.addEventListener("click", function() {
let currentBtn = item;
let tabId = currentBtn.getAttribute("data-tab");
let currentTub = document.querySelector(tabId);
if(currentBtn.classList.contains('active')){
currentBtn.classList.remove('active');
currentTub.classList.remove('active');
} else if ( ! currentBtn.classList.contains('active') ) {
tabsBtn.forEach(function(item) {
item.classList.remove('active');
});
tabsItems.forEach(function(item) {
item.classList.remove('active');
});
currentBtn.classList.add('active');
currentTub.classList.add('active');
}
});
}
$arr = array(
'/category0/subcat1/subcat2',
'/category0/subcat1/subcat4',
'/category0/subcat5/subcat6',
'/category2/subcat7/subcat8',
'/category2/subcat9/subcat10',
'/category2/subcat11/subcat12'
);
foreach ($arr as $key => $value) {
preg_match_all('#/category(\d+)/subcat(\d+)/subcat(\d+)#', $value, $newmatch);
$cats[] = array('category' => $newmatch[1][0], 'subcat' => $newmatch[2][0], 'subcat_' => $newmatch[3][0]);
unset($newmatch);
}
print_r($cats);
Array
(
[0] => Array
(
[category] => 0
[subcat] => 1
[subcat_] => 2
)
[1] => Array
(
[category] => 0
[subcat] => 1
[subcat_] => 4
)
[2] => Array
(
[category] => 0
[subcat] => 5
[subcat_] => 6
)
[3] => Array
(
[category] => 2
[subcat] => 7
[subcat_] => 8
)
[4] => Array
(
[category] => 2
[subcat] => 9
[subcat_] => 10
)
[5] => Array
(
[category] => 2
[subcat] => 11
[subcat_] => 12
)
)
<?php
$str = "<a class=\"like\" href=\"site1=site2\" onclick=\"ga('send', 'event', 'outbound', 'click', 'google.ru/music_save/');metrika_goal('music_save');\">сохранить трек</a>";
echo ChangeHref($str, 'like' ,'https://www.google.com/');
function ChangeHref($str, $class, $link){
return preg_replace('#(<a[^>]*class="[^"]*'.$class.'[^"]*"[^>]*href=")([^>])*("[^>]*>)#', "$1". $link. "$3", $str);
}
?>
$text = mysqli_real_escape_string($conn, $text); //Для $conn
$text = $mysqli->real_escape_string($text); //Для $mysqli