function phone_format($phone){ $d=preg_replace('~\D+~','',$phone); if(strlen($d)>=10){ $d10=substr($d,-10,10); return '+7 ('.substr($d10,0,3).') '.substr($d10,3,3).'-'.substr($d10,6,2).'-'.substr($d10,8,2); } elseif(strlen($d)==7){ return '+7 (812) '.substr($d,0,3).'-'.substr($d,3,2).'-'.substr($d,5,2); } else{ return $phone; } }
Архив
2021 год
Всего: 40 записей
плавающий блок в пределах родительского
$.fn.stickyfloat=function(options,lockBottom){ var $obj=this; var parentPaddingTop=parseInt($obj.parent().css('padding-top')); var startOffset=$obj.parent().offset().top; var opts=$.extend({startOffset:startOffset,offsetY:parentPaddingTop,duration:200,lockBottom:true},options); $obj.css({position:'absolute'}); if(opts.lockBottom){ var bottomPos=$obj.parent().height()-$obj.height()+parentPaddingTop; if(bottomPos<0) bottomPos=0; } $(window).scroll(function(){ $obj.stop(); var pastStartOffset=$(document).scrollTop()>opts.startOffset; var objFartherThanTopPos=$obj.offset().top>startOffset; var objBiggerThanWindow=$obj.outerHeight()<$(window).height(); if((pastStartOffset||objFartherThanTopPos)&&objBiggerThanWindow){ var newpos=($(document).scrollTop()-startOffset+opts.offsetY); if(newpos>bottomPos) newpos=bottomPos; if($(document).scrollTop()<opts.startOffset) newpos=parentPaddingTop; $obj.animate({top:newpos},opts.duration); } }); };
Пример использования:
$(document).ready(function(){ setTimeout(function(){ $('#main .left').css('min-height',$('#main').height()); $('#main .inner').stickyfloat({duration:500}); },2000); });
<div id="main"> <div class="left"> <div class="inner">content</div> </div> <div class="right"></div> <div class="clear"></div> </div>
.left,.right{ width:50%; } .left{ position:relative; float:left; } .right{ float:right; } .clear{ clear:both; }
Источник: https://ruseller.com/lessons.php?id=999&rub=32
maskedinput курсор в начало
$.fn.setCursorPosition=function(pos){ if($(this).get(0).setSelectionRange){ $(this).get(0).setSelectionRange(pos,pos); } else if($(this).get(0).createTextRange){ var range=$(this).get(0).createTextRange(); range.collapse(true); range.moveEnd('character',pos); range.moveStart('character',pos); range.select(); } }; function set_mask_cursor(){ $('input[name="phone"]').on('click',function(){ $(this).setCursorPosition(4); }); $('input[name="code"]').on('click',function(){ $(this).setCursorPosition(0); }); } $(document).ready(function(){ $("input[name=phone]").mask("+7 (999) 999-99-99"); $("input[name=code]").mask("9999"); set_mask_cursor(); });
input:-internal-autofill-selected remove
Убрать фон:
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus, input:-webkit-autofill:active{ -webkit-box-shadow:0 0 0 30px #ffffff inset !important; }
Изменить цвет текста:
input:-webkit-autofill{ -webkit-text-fill-color:#c05857 !important; }
file_get_contents(): SSL operation failed with code 1
При:
$cities_get=file_get_contents(LOS_URL.'ajax.php?type=cities');
Ошибка:
<br /> <b>Warning</b>: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in <b>/var/www/site.ru/index.php</b> on line <b>241</b><br /> <br /> <b>Warning</b>: file_get_contents(): Failed to enable crypto in <b>/var/www/site.ru/index.php</b> on line <b>241</b><br /> <br /> <b>Warning</b>: file_get_contents(https://site.su/ajax.php?type=cities): failed to open stream: operation failed in <b>/var/www/site.ru/index.php</b> on line <b>241</b><br />
Решение:
$arrContextOptions=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); $cities_get=file_get_contents(LOS_URL.'ajax.php?type=cities',false,stream_context_create($arrContextOptions));
javascript timestamp to date
new Date(1632822057*1000).toLocaleDateString("ru-RU")
owl carousel autoplay on hover
Без циклической прокрутки:
var owl_catalog_item=$('.owl_catalog_item'); owl_catalog_item.owlCarousel({ items:1, loop:false, margin:0, autoplay:true, autoplayTimeout:1000, autoplayHoverPause:false, dots:false, nav:false, navText:['<i class="fa fa-angle-left"></i>','<i class="fa fa-angle-right"></i>'], responsive:{ 0:{ }, 480:{ }, 768:{ } } }); owl_catalog_item.trigger('stop.owl.autoplay'); $('.catalog .item').on('mouseenter',function(){ if($(this).find('.owl_catalog_item a').length>1){ $(this).find('.owl_catalog_item').trigger('play.owl.autoplay',[1000]); } }); $('.catalog .item').on('mouseleave',function(){ $(this).find('.owl_catalog_item').trigger('stop.owl.autoplay'); $(this).find('.owl_catalog_item').trigger('to.owl.carousel',0); });
С циклической прокруткой:
var owl_catalog_item=$('.owl_catalog_item'); owl_catalog_item.owlCarousel({ items:1, loop:true, margin:0, autoplay:true, autoplayTimeout:1000, autoplayHoverPause:false, dots:false, nav:false, navText:['<i class="fa fa-angle-left"></i>','<i class="fa fa-angle-right"></i>'], responsive:{ 0:{ }, 480:{ }, 768:{ } } }); owl_catalog_item.trigger('stop.owl.autoplay'); $('.catalog .item').on('mouseenter',function(){ $(this).find('.owl_catalog_item').trigger('play.owl.autoplay',[1000]); }) $('.catalog .item').on('mouseleave',function(){ $(this).find('.owl_catalog_item').trigger('stop.owl.autoplay'); });