是否可以只为toggleClass的remove class部分添加延迟?
在小提琴中,我希望红色div在点击时立即变为绿色。 但是再次点击它会延迟回到红色。
http://jsfiddle.net/simbasounds/ggk8xxya/1/
HTML
<div class="container">
I am a div
</div>
CSS
.container {
padding: 10px;
background: red;
}
.container.green {
background: green;
}
的jQuery
$(".container").click(function(){
$(this).toggleClass('green');
});
答案 0 :(得分:2)
显而易见的方法呢?
$(".container").click(function(){
if ($(this).hasClass('green')) {
// add your delay here
}
else {
$(this).toggleClass('green');
}
});
答案 1 :(得分:1)
从绿色转换为红色时的简单时间延迟
func saveOperativesInModel() {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext!
let entity = NSEntityDescription.entityForName("Operatives", inManagedObjectContext: managedContext)
var item: NSManagedObject!
if let operativesList = self.operativesResult?.operativesList {
self.operativesTable.removeAll()
for itemInArray in operativesList {
item = NSManagedObject(entity: entity!, insertIntoManagedObjectContext:managedContext)
item.setValue(itemInArray.firstName, forKey: "firstName")
var error: NSError?
if !managedContext.save(&error) {
} else {
self.operativesTable.append(item!)
println("saveOperativesInModel: \(itemInArray.firstName)")
}
}
}
let fetchRequest1: NSFetchRequest! = NSFetchRequest(entityName:"Operatives")
let fetchedResults = managedContext.executeFetchRequest(fetchRequest1, error: &error) as? [NSManagedObject]
if let operativesTable = fetchedResults {
if operativesTable.count > 0 {
for item in operativesTable {
let operative: Operative! = Operative()
operative.firstName = String (stringInterpolationSegment: item.valueForKey("firstName"))
println("getOperativesFromModel: \(operative.firstName)")
}
}
}
}