王新阳

wangxinyang

iscroll仿系统滚动插件

http://caibaojian.com/iscroll-5/

https://segmentfault.com/a/1190000003113280

https://blog.csdn.net/amyloverice/article/details/79383712

http://www.jq22.com/jquery-info13446

CDN https://www.bootcdn.cn/iScroll/

最简单的js日历

<meta charset="utf-8">
<div id="calendar"></div>
<script>
/**
 * edgesun@126.com
 * 20190207
 */
function myCalendar(YEAR,MONTH){
	function isLng(num){return /^(0|([1-9]\d*))$/.test(''+num);}
	var myDate=new Date(), today={year:myDate.getFullYear(), month:myDate.getMonth(), date:myDate.getDate(), ymd:''}; //当前日期
	today.ymd = today.year+ (today.month<9?'0':'')+(today.month+1)+(today.date<10?'0':'')+today.date;
	if(isLng(YEAR) && isLng(MONTH)){
		if(YEAR<2010 || YEAR>2037){alert('不能再翻啦~');return;}
		if(MONTH>11){alert('参数month应该为0到11的整数');return;}
		myDate.setFullYear(YEAR, MONTH, 1);
	}else{
		YEAR = today.year;
		MONTH = today.month;
	}
	
	var PrevNext=[[0,0],[0,0]]; //依次为上一月的年、月,下一月的年、月
	if(MONTH==0){
		PrevNext = [[YEAR-1,11],[YEAR,1]];
	}else if(MONTH==11){
		PrevNext = [[YEAR,10],[YEAR+1,0]];
	}else{
		PrevNext = [[YEAR,MONTH-1],[YEAR,MONTH+1]];
	}
	
	myDate.setDate(1); //当前显示月的第一天
	var weekday=myDate.getDay()?myDate.getDay():7; //当前显示月的第一天是星期几(星期天重置为7,即每周最后一天)
	myDate.setMonth(MONTH+1);
	myDate.setDate(0);
	var totalDays = myDate.getDate(); //当前显示月的总天数
	var html='<table width="100%" border="1" cellpadding="5" cellspacing="0"><thead><tr><th onclick="myCalendar('+PrevNext[0][0]+','+PrevNext[0][1]+')">上个月</th><th colspan="5">'+YEAR+'年'+(MONTH+1)+'月</th><th onClick="myCalendar('+PrevNext[1][0]+','+PrevNext[1][1]+')">下个月</th></tr><tr><th>星期一</th><th>星期二</th><th>星期三</th><th>星期四</th><th>星期五</th><th>星期六</th><th>星期日</th></tr></th><tbody>';
	var n=0, ymd='';
	for(var i=1; i<=42; ++i){
		if(i%7==1) html+='<tr>';
		if(i>=weekday && i<totalDays+weekday){
			++n;
			ymd=''+YEAR+(MONTH<9?'0':'')+(MONTH+1)+(n<10?'0':'')+n;
			html+='<td'+(ymd==today.ymd?' style="background-color:#ddf;"':'')+' data-date="'+ymd+'">'+n+'</td>';
		}else{
			html+='<td></td>';
		}
		if(i%7==0){
			html+='</tr>';
			if(i>=(totalDays+weekday-1))break;
		}
	}
	html+='</tbody></table>';
	document.getElementById('calendar').innerHTML=html;
}

myCalendar();
</script>

一个不错的js颜色选择器

https://github.com/claviska/jquery-minicolors

演示: http://www.jq22.com/jquery-info204

更多js拾色器:http://www.jq22.com/jquery-plugins%E6%8B%BE%E8%89%B2%E5%99%A8-1-jq

如果同步设置input背景色,可能会出现input内text颜色与背景色难以区分的情况,可以使用如下方法自动设置文字颜色:(hex为获取到的颜色,如:#ffcc00)

var r = parseInt(hex.substr(1, 2), 16);
var g = parseInt(hex.substr(3, 2), 16);
var b = parseInt(hex.substr(5, 2), 16);
var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
$(this).css({'background-color':hex, 'color': (yiq >= 128) ? 'black' : 'white'});

配置:

$('.js-color-input').each( function() {
	$(this).minicolors({
		control: $(this).attr('data-control') || 'hue',
		defaultValue: $(this).attr('data-defaultValue') || '#ff0000',
		format: $(this).attr('data-format') || 'hex',
		keywords: $(this).attr('data-keywords') || '',
		inline: $(this).attr('data-inline') === 'true',
		letterCase: $(this).attr('data-letterCase') || 'lowercase',
		opacity: $(this).attr('data-opacity'),
		position: $(this).attr('data-position') || 'bottom',
		swatches: $(this).attr('data-swatches') ? $(this).attr('data-swatches').split('|') : [],
		change: function(hex, opacity){
			if(! hex)return;
			var r = parseInt(hex.substr(1, 2), 16);
			var g = parseInt(hex.substr(3, 2), 16);
			var b = parseInt(hex.substr(5, 2), 16);
			var yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
			$(this).css({'background-color':hex, 'color': (yiq >= 128) ? 'black' : 'white'});
		},
		theme: 'default',
	});
});


wow.js与fullpage.js结合使用时失效的解决办法

第一屏可以正常显示,从第二屏开始,使用wow效果的元素就不显示了 visibility:hidden;

原因:fullpage.js 配置中使用了 scrollBar:false,隐藏了滚动条,wow无法判断滚动条位置。

解决办法:fullpage.js配置中显示滚动条 scrollBar:true,然后使用css中隐藏滚动条 body{overflow:hidden !important;}。不能直接在<body>标签上设置style,会被fullpage.js重置overflow值。

如果还不行就在fullpage运行后执行wow,设置方法: $('#fullpage').fullpage({afterRender: function(){new WOW().init();}});。我程序中这两个的执行顺序并没有影响,看别人这么说的,记录下。

wow.js

http://mynameismatthieu.com/WOW/

https://github.com/matthieua/WOW

http://570109268.iteye.com/blog/2411836

https://www.cnblogs.com/yangjunfei/p/6746926.html

<link rel="stylesheet" type="text/css" href="css/animate.min.css">
<script type="text/javascript" src="js/wow.min.js"></script>
<script type="text/javascript">new WOW().init();</script>

<div class="wow slideInLeft" data-wow-duration="2s" data-wow-delay="5s" data-wow-offset="10"  data-wow-iteration="10"></div>

类名前面的wow是每一个带动画的元素都要加的,slideInLeft就是说明动画样式。后面的data-wow-duration(动画持续时间)、data-wow-delay(动画延迟时间)、data-wow-offset(元素的位置露出后距离底部多少像素执行)和data-wow-iteration(动画执行次数)这四个属性可选可不选。

fullpage滚动到第二屏后wow失效的解决方法:
1、fullpage配置中 scrollBar : true
2、css body{overflow:hidden !important;}

jquery.fullpage.js

使用方法:

详细 https://www.cnblogs.com/EnSnail/p/5880385.html

http://www.dowebok.com/77.html

https://www.cnblogs.com/windy-xmwh/p/8279635.html

演示 http://www.shouce.ren/post/view/id/113203

https://www.jb51.net/article/98824.htm

说明,演示 http://www.jq22.com/jquery-info1124

js阻止事件冒泡的两种方法

<div>
	<input type="button" value="submit">
</div>

方法一:event.stopPropagation( );

$("input").click(function(event){
    alert('click');
    event.stopPropagation(); //阻止冒泡
});

方法二:event.target

现在,事件处理程序中的变量event保存着事件对象。而event.target属性保存着发生事件的目标元素。这个属性是DOM API中规定的,但是没有被所有浏览器实现 。jQuery对这个事件对象进行了必要的扩展,从而在任何浏览器中都能够使用这个属性。通过.target,可以确定DOM中首先接收到事件的元素(即实际被单击的元素)

$("input").click(function(event){
    if(event.target != this)return; //阻止冒泡
    alert("click");
});

bootstrap-datetimepicker 详解

http://www.bootcss.com/p/bootstrap-datetimepicker/

需要bootstrap的下拉菜单组件 (dropdowns.less) 的某些样式,还有bootstrap的sprites (sprites.less and associated images) 中的箭头图标。

A standalone .css file (including necessary dropdown styles and alternative, text-based arrows) can be generated by running build/build_standalone.less through the lessc compiler:

  1. $ lessc build/build_standalone.less datetimepicker.css

所有需要"Date" 的选项都可以处理Date 对象; a String formatted according to the given format; or a timedelta relative to today, eg '-1d', '+6m +1y', etc, where valid units are 'd' (day), 'w' (week), 'm' (month), and 'y' (year).

你也可以指定一个符合 ISO-8601 格式的日期时间,就可以忽略下面的格式:

  • yyyy-mm-dd
  • yyyy-mm-dd hh:ii
  • yyyy-mm-ddThh:ii
  • yyyy-mm-dd hh:ii:ss
  • yyyy-mm-ddThh:ii:ssZ

format

String. 默认值: 'mm/dd/yyyy'

日期格式, p, P, h, hh, i, ii, s, ss, d, dd, m, mm, M, MM, yy, yyyy 的任意组合。

  • p : meridian in lower case ('am' or 'pm') - according to locale file
  • P : meridian in upper case ('AM' or 'PM') - according to locale file
  • s : seconds without leading zeros
  • ss : seconds, 2 digits with leading zeros
  • i : minutes without leading zeros
  • ii : minutes, 2 digits with leading zeros
  • h : hour without leading zeros - 24-hour format
  • hh : hour, 2 digits with leading zeros - 24-hour format
  • H : hour without leading zeros - 12-hour format
  • HH : hour, 2 digits with leading zeros - 12-hour format
  • d : day of the month without leading zeros
  • dd : day of the month, 2 digits with leading zeros
  • m : numeric representation of month without leading zeros
  • mm : numeric representation of the month, 2 digits with leading zeros
  • M : short textual representation of a month, three letters
  • MM : full textual representation of a month, such as January or March
  • yy : two digit representation of a year
  • yyyy : full numeric representation of a year, 4 digits

weekStart

Integer. 默认值:0

一周从哪一天开始。0(星期日)到6(星期六)

startDate

Date. 默认值:开始时间

The earliest date that may be selected; all earlier dates will be disabled.

endDate

Date. 默认值:结束时间

The latest date that may be selected; all later dates will be disabled.

daysOfWeekDisabled

String, Array. 默认值: '', []

Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: '0,6' or [0,6].

autoclose

Boolean. 默认值:false

当选择一个日期之后是否立即关闭此日期时间选择器。

startView

Number, String. 默认值:2, 'month'

日期时间选择器打开之后首先显示的视图。 可接受的值:

  • 0 or 'hour' for the hour view
  • 1 or 'day' for the day view
  • 2 or 'month' for month view (the default)
  • 3 or 'year' for the 12-month overview
  • 4 or 'decade' for the 10-year overview. Useful for date-of-birth datetimepickers.

minView

Number, String. 默认值:0, 'hour'

日期时间选择器所能够提供的最精确的时间选择视图。

maxView

Number, String. 默认值:4, 'decade'

日期时间选择器最高能展示的选择范围视图。

todayBtn

Boolean, "linked". 默认值: false

如果此值为true 或 "linked",则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。如果是true的话,"Today" 按钮仅仅将视图转到当天的日期,如果是"linked",当天日期将会被选中。

todayHighlight

Boolean. 默认值: false

如果为true, 高亮当前日期。

keyboardNavigation

Boolean. 默认值: true

是否允许通过方向键改变日期。

language

String. 默认值: 'en'

The two-letter code of the language to use for month and day names. These will also be used as the input's value (and subsequently sent to the server in the case of form submissions). Currently ships with English ('en'), German ('de'), Brazilian ('br'), and Spanish ('es') translations, but others can be added (see I18N below). If an unknown language code is given, English will be used.

forceParse

Boolean. 默认值: true

当选择器关闭的时候,是否强制解析输入框中的值。也就是说,当用户在输入框中输入了不正确的日期,选择器将会尽量解析输入的值,并将解析后的正确值按照给定的格式format设置到输入框中。

minuteStep

Number. 默认值: 5

此数值被当做步进值用于构建小时视图。对于每个 minuteStep 都会生成一组预设时间(分钟)用于选择。

pickerReferer : 不建议使用

String. 默认值: 'default' (other value available : 'input')

The referer element to place the picker for the component implementation. If you want to place the picker just under the input field, just specify input.

pickerPosition

String. 默认值: 'bottom-right' (还支持 : 'bottom-left')

此选项当前只在组件实现中提供支持。通过设置选项可以讲选择器放倒输入框下方。

viewSelect

Number or String. 默认值: same as minView (supported values are: 'decade', 'year', 'month', 'day', 'hour')

With this option you can select the view from which the date will be selected. By default it's the last one, however you can choose the first one, so at each click the date will be updated.

showMeridian

Boolean. 默认值: false

This option will enable meridian views for day and hour views.

initialDate

Date or String. 默认值: new Date()

You can initialize the viewer with a date. By default it's now, so you can specify yesterday or today at midnight ...

组件模版。

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input class="span2" size="16" type="text" value="12-02-2012">
  3. <span class="add-on"><i class="icon-th"></i></span>
  4. </div>

带有重置按钮(用于清空输入框)的组件模版。

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input class="span2" size="16" type="text" value="12-02-2012">
  3. <span class="add-on"><i class="icon-remove"></i></span>
  4. <span class="add-on"><i class="icon-th"></i></span>
  5. </div>

.datetimepicker(options)

初始化日期时间选择器。

remove

参数: None

移除日期时间选择器。同时移除已经绑定的event、内部绑定的对象和HTML元素。

  1. $('#datetimepicker').datetimepicker('remove');

show

参数: None

显示日期时间选择器。

  1. $('#datetimepicker').datetimepicker('show');

hide

参数: None

隐藏日期时间选择器。

  1. $('#datetimepicker').datetimepicker('hide');

update

参数: None

使用当前输入框中的值更新日期时间选择器。

  1. $('#datetimepicker').datetimepicker('update');

setStartDate

参数:

  • startDate (String)

给日期时间选择器设置一个新的起始日期。

  1. $('#datetimepicker').datetimepicker('setStartDate', '2012-01-01');

Omit startDate (or provide an otherwise falsey value) to unset the limit.

  1. $('#datetimepicker').datetimepicker('setStartDate');
  2. $('#datetimepicker').datetimepicker('setStartDate', null);

setEndDate

参数:

  • endDate (String)

给日期时间选择器设置结束日期。

  1. $('#datetimepicker').datetimepicker('setEndDate', '2012-01-01');

Omit endDate (or provide an otherwise falsey value) to unset the limit.

  1. $('#datetimepicker').datetimepicker('setEndDate');
  2. $('#datetimepicker').datetimepicker('setEndDate', null);

setDaysOfWeekDisabled

参数:

  • daysOfWeekDisabled (String|Array)

Sets the days of week that should be disabled.

  1. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled', [0,6]);

Omit daysOfWeekDisabled (or provide an otherwise falsey value) to unset the disabled days.

  1. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled');
  2. $('#datetimepicker').datetimepicker('setDaysOfWeekDisabled', null);

Datetimepicker 类暴露了一组event用以对日期进行操作。

show

当选择器显示时被触发。

hide

当选择器隐藏时被触发。

changeDate

当日期被改变时被触发。

  1. $('#date-end')
  2. .datetimepicker()
  3. .on('changeDate', function(ev){
  4. if (ev.date.valueOf() < date-start-display.valueOf()){
  5. ....
  6. }
  7. });

changeYear

当十年视图上的年视图view被改变时触发。

changeMonth

当年视图上的月视图view被改变时触发。

outOfRange

当用户选择的日期超出startDate 或endDate 时,或者通过setDate 或 setUTCDate方法设置日期超出范围时被触发。

日期时间选择器提供了键盘导航:

up, down, left, right 方向键

这些方向键中,left/right 向后/向前 一天,up/down 向后/向前 一周。

配合shift键,up/left 向后退一个月,down/right 向前进一个月。

配置ctrl键,up/left 向后退一年,down/right 向前进一年。

Shift+ctrl 和 ctrl 同等效果 - 也就是说,他们不能同时改变月和年,只能单独改变年。

escape

escape 键可以用来隐藏、重新显示日期时间选择器;当用户希望手工编辑输入框中的值是会很有用。

enter

当选择器处于显示状态时,enter键只是将其隐藏。当选择器处于隐藏状态时,enter键发挥通常的功能 - 提交当前表单,或者其他。

本插件支持月、每周中天的名称、weekStart选项的国际化。默认是语言是English ('en');其它可以使用的翻译文件在js/locales/ 目录中,只需在本插件之后引入需要的语言文件即可。需要增加额外语言支持的话,只需向 $.fn.datetimepicker.dates中增加一个key即可,一定要放在调用 .datetimepicker()之前。如下案例:

  1. $.fn.datetimepicker.dates['en'] = {
  2. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
  3. daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  4. daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
  5. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  6. monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  7. today: "Today"
  8. };

Right-to-left languages may also include rtl: true to make the calendar display appropriately.

If your browser (or those of your users) is displaying characters wrong, chances are the browser is loading the javascript file with a non-unicode encoding. Simply add charset="UTF-8" to your script tag:

  1. <script type="text/javascript" src="bootstrap-datetimepicker.de.js" charset="UTF-8"></script>

绑定输入框,并设置format选项:

  1. <input type="text" value="2012-05-15 21:05" id="datetimepicker">
  1. $('#datetimepicker').datetimepicker({
  2. format: 'yyyy-mm-dd hh:ii'
  3. });

绑定输入框,并设置format标记:

  1. <input type="text" value="2012-05-15 21:05" id="datetimepicker" data-date-format="yyyy-mm-dd hh:ii">
  1. $('#datetimepicker').datetimepicker();

作为组件使用:

  1. <div class="input-append date" id="datetimepicker" data-date="12-02-2012" data-date-format="dd-mm-yyyy">
  2. <input size="16" type="text" value="12-02-2012" readonly>
  3. <span class="add-on"><i class="icon-th"></i></span>
  4. </div>
  1. $('#datetimepicker').datetimepicker();

作为内联日期时间选择器:

  1. <div id="datetimepicker"></div>
  1. $('#datetimepicker').datetimepicker();

js的传值与传址

传值:
var a = 5,b = a;
b = 8;
alert( a);

这时你发现返回5,即a的值根本没有变化,传值是Javascript基本数据类型(数字、字符串、布尔值)被操作的过程,在值被操作过程中,对实际的值做了一份copy,这份copy存在了另一个变量或对象属性或数组元素中,copy的值和原来的值是两份完全独立的值,如果修改了copy的值,那么原值并不会发生改变。

传址:
var obj1=new Object(),obj2 = obj1
obj1.name = "asdsadas";
alert(obj2.name);

这时你会发现返回了asdsadas,可明明修改的是obj1中的name,obj2的name怎么也跟着变化了?传址在Javascript中主要指针对引用类型(对象、数组、函数)的值的操作过程,obj2 = obj1; 这一句将obj1赋值给了obj2,这样也会将原值copy一份放到新变量的空间中,不同的是,这个值的副本实际上是一个指针,指针指向原值的对象,当改变其中任一个变量(或对象的属性)时,另一个的值也会发生变化。


作者:丁小倪
链接:https://www.zhihu.com/question/20133110/answer/14081804

Swiper4.x使用方法

Swiper4.x API文档 http://www.swiper.com.cn/api/index.html

官方演示:https://www.swiper.com.cn/demo/index.html

1.首先加载插件,需要用到的文件有swiper.min.js和swiper.min.css文件。可下载Swiper文件或使用CDN

<!DOCTYPE html>
<html>
<head>
    ...
    <link rel="stylesheet" href="path/to/swiper.min.css">
</head>
<body>
    ...
    <script src="path/to/swiper.min.js"></script>
</body>
</html>

2.HTML内容。

<div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide">Slide 1</div>
        <div class="swiper-slide">Slide 2</div>
        <div class="swiper-slide">Slide 3</div>
    </div>
    <!-- 如果需要分页器 -->
    <div class="swiper-pagination"></div>
    
    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
    
    <!-- 如果需要滚动条 -->
    <div class="swiper-scrollbar"></div>
</div>
导航等组件可以放在container之外

3.你可能想要给Swiper定义一个大小,当然不要也行。

.swiper-container {
    width: 600px;
    height: 300px;
}  

4.初始化Swiper:最好是挨着</body>标签

<script>        
  var mySwiper = new Swiper ('.swiper-container', {
    direction: 'vertical',
    loop: true,
    
    // 如果需要分页器
    pagination: {
      el: '.swiper-pagination',
    },
    
    // 如果需要前进后退按钮
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    
    // 如果需要滚动条
    scrollbar: {
      el: '.swiper-scrollbar',
    },
  })        
  </script>
</body>

如果不能写在HTML内容的后面,则需要在页面加载完成后再初始化。

<script type="text/javascript">
window.onload = function() {
  ...
}
</script>

或者这样(Jquery和Zepto)

<script type="text/javascript">
$(document).ready(function () {
 ...
})
</script>

5.完成。恭喜你,现在你的Swiper应该已经能正常切换了。

var Swiper = new Swiper('.swiper-container', {
	autoplay: {
		delay: 3e3, //自动切换的时间间隔
		stopOnLastSlide: false, //切换到最后一个时停止自动切换(loop模式下无效)
		disableOnInteraction: false, //用户操作swiper之后停止自动播放
	},
	effect : 'slide', //切换效果slide/fade/cube/flip
	slidesPerView: 1, //每页slide个数
	spaceBetween: 0, //两个slide的间距
	loop: false, //循环
	//direction : 'horizontal', //滚动方向horizontal/vertical
	//speed:300, //动画持续时间
	pagination: { //分页器
		el: '.swiper-pagination',
		type: 'bullets', //式样bullets/fraction/progressbar
		clickable: true,
	},
	navigation: { //前进后退按钮
		nextEl: '.swiper-button-next',
		prevEl: '.swiper-button-prev',
	},
});

Swiper全屏自适应焦点图轮播
https://www.lanrenzhijia.com/banner/6089.html

动态改变每屏slide的数量
1、初始化时设置每屏slide数量为auto。slidesPerView : 'auto'
2、css响应式设置每个slide的宽度 @media(max-width:1399px){ .swiper-slide{width:25%;} }

2024-05-14 星期二 农历四月初七