Skip to content

Instantly share code, notes, and snippets.

View 3014zhangshuo's full-sized avatar
🎯
Coding

张硕 3014zhangshuo

🎯
Coding
View GitHub Profile
@3014zhangshuo
3014zhangshuo / operations_range_of_numbers.md
Created September 20, 2017 04:48 — forked from CodeRecipez/operations_range_of_numbers.md
Sass 101 - A newb's guide: Operations range of numbers

The @for directive repeatedly outputs a set of styles. For each repetition, a counter variable is used to adjust the output. The directive has two forms: @for $var from <start> through <end> and @for $var from <start> to <end>.

Note the difference in the keywords through and to. $var can be any variable name, like $i; <start> and <end> are SassScript expressions that should return integers.

The @for statement sets $var to each successive number in the specified range and each time outputs the nested styles using that value of $var. For the form from <start> through <end>, the range includes the values of <start> and <end>, but the form from <start> to <end> runs up to but not including the value of <end>.

from <start> through <end>

$cols: 2;
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
@3014zhangshuo
3014zhangshuo / blur-auto-submit.js
Created August 29, 2017 09:07
form blur(click to other space)auto submit
var queueSubmit;
$('#sample input').each(function(i,e){
$(this).bind('focus',function(){
clearTimeout(queueSubmit);
});
$(this).bind('blur',function(){
queueSubmit = setTimeout(function(){ $('#sample').submit(); }, 1000);
});
});
// 防止后退键编程
function suppressBackspace(evt) {
evt = evt || window.event;
var target = evt.target || evt.srcElement;
if (evt.keyCode == 8 && !/div|ul|li/i.test(target.nodeName)) {
return false;
}
}
document.onkeydown = suppressBackspace;
@3014zhangshuo
3014zhangshuo / limit-file-size.js
Created August 26, 2017 02:43
图片过大的前端判断
function validateFiles(inputFile) {
var maxExceededMessage = "This file exceeds the maximum allowed file size (5 MB)";
var extErrorMessage = "Only image file with extension: .jpg, .jpeg, .gif or .png is allowed";
var allowedExtension = ["jpg", "jpeg", "gif", "png"];
var extName;
var maxFileSize = $(inputFile).data('max-file-size');
var sizeExceeded = false;
var extError = false;
$.each(inputFile.files, function() {
$('#scroll-down').on('scroll', function(e){
e.preventDefault();
if($(this).scrollTop() + $(this).innerHeight()>=$(this)[0].scrollHeight){
var id = $('.ajax-show-example').last().data('id');
var category = $('select[name=tag]').val();
var size = $('select[name=entry_size]').val();
var type = $('select[name=entry_type]').val();
$.ajax({
url: '<%= append_example_example_entries_path %>',
type: 'get',
@3014zhangshuo
3014zhangshuo / dropdown-list-search.js
Created August 25, 2017 12:02
根据已有的下拉框内容进行搜索
$(document).ready(function(){
$('.logo-live-search-list li').each(function(){
$(this).attr('data-search-term', $(this).text());
});
$('.logo-live-search-box').on('keyup', function(){
var searchTerm = $(this).val();
$('.logo-live-search-list li').each(function(){
if ($(this).filter('[data-search-term *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
$(this).show();
} else {
@3014zhangshuo
3014zhangshuo / 简历自动建议系统.js
Created August 25, 2017 11:59
简历自动建议系统
$('#resume-score').click(function(){
$('#suggestion').html('') //防止多次点击后出现重复提示信息
$('#suggestion').removeClass('hide')
$('#suggestion').append('<%= j render :partial => "student/resumes/loading2" %>');
function show(){
var total = $('#clear-s-brackets').html().toString()
if (total.match('www') || total.match('http')) {
$('#suggestion').append('<li>建议使用编辑器自带的添加链接功能</li>')
}
@3014zhangshuo
3014zhangshuo / coffee.js
Created August 25, 2017 10:57
carrierwave cropper
jQuery ->
new CarrierWaveCropper()
class CarrierWaveCropper
constructor: ->
$('#resume_user_avatar_cropbox').Jcrop
# aspectRatio: 1
aspectRatio: 0.7878
setSelect: [0, 0, 260, 320]
boxWidth: 350
@3014zhangshuo
3014zhangshuo / jquery.editable.js
Created August 8, 2017 05:53 — forked from tom--/jquery.editable.js
jquery plugin to make contenteditable text trigger a change event when it changes
(function ($) {
'use strict';
/**
* Makes contenteditable elements within a container generate change events.
*
* When you do, e.g. $obj.editable(), all the DOM elements with attribute contenteditable
* that are children of the DOM element $obj will trigger a change event when their
* contents is edited and changed.
*
* See: http://html5demos.com/contenteditable