I am doing a jQuery animation of 3 boxes, the effect is like the jsfiddle link below:
Fiddle
Basically when clicked on each color box the corresponding box will enlarge to width 100% taking up all width. And when clicking close (yes, it is not functioning well) the box will shrink back to its original position.
What I encountered now is
When enlarging the pink or the blue box, sometimes the yellow box on RHS will jump to next row (but just a very quick jump, i dunno why). It happens only in Chrome, looks perfect in Firefox.
When clicking the close button, it will trigger the yellow box to
enlarge (supposed it has taken up 0% of width? Why the bind click
still works?
Could someone advise how I should solve these and is there a better way for me to achieve the same results?
HTML
<div class="animateWrap">
<div id="btn_howtojoin" class="btn_group">
<div class="btn_close"></div>
<div class="content">Content</div>
</div>
<div id="btn_judgecriteria" class="btn_group">
<div class="btn_close"></div>
<div class="content">Content</div>
</div>
<div id="btn_prizeinfo" class="btn_group">
<div class="btn_close">Close</div>
<div class="content">Content</div>
</div>
<div class="clear00"></div>
JS
$(function () {
$('#btn_judgecriteria').bind('click', function () {
$(this).animate({
width: "100%"
}, function () {
$(this).animate({
height: "400px"
});
$('.btn_close').show();
});
$('#btn_prizeinfo').animate({
width: "0%"
});
$('#btn_howtojoin').animate({
width: "0%"
});
});
$('#btn_howtojoin').bind('click', function () {
$(this).animate({
width: "100%"
}, function () {
$(this).animate({
height: "400px"
});
$(this).find('.content').animate({
top: "40px"
});
$('.btn_close').show();
});
$('#btn_prizeinfo').animate({
width: "0%"
});
$('#btn_judgecriteria').animate({
width: "0%"
});
});
$('#btn_prizeinfo').bind('click', function () {
$(this).animate({
width: "100%"
}, function () {
$(this).animate({
height: "400px"
});
$('.btn_close').show();
});
$('#btn_howtojoin').animate({
width: "0%"
});
$('#btn_judgecriteria').animate({
width: "0%"
});
});
$('.btn_close').bind('click', function () {
$('.btn_group').animate({
width: "33.333%",
height: "220px"
});
$('.btn_group .content').hide();
$('.btn_close').hide();
});
});
CSS
.btn_group {
width: 33.3%;
height: 220px;
float: left;
cursor: pointer;
position:relative;
}
#btn_howtojoin {
background: #fcb2b2 ;
width: 33.4%;
}
#btn_judgecriteria {
background: #7acccb ;
}
#btn_prizeinfo {
background: #f1c348;
}
.btn_group .content {
position:absolute;
top:-400px;
left:40px;
}
.btn_close {
position:absolute;
top:20px;
right:20px;
color:#FFF;
width: 40px;
height:62px;
display:none;
}
Problem 1 maybe due to rounding up calculation of 33.333% which make the total width of 3 container slightly larger than 100%. Changing them to pixel might help.
Problem 2 is due to event bubbling, it will trigger click event of .btn_group after .btn_close
Add event.stopPropagation(); will help solving this.
$('.btn_close').bind('click', function () {
$('.btn_group').animate({
width: "33.333%",
height: "220px"
});
$('.btn_group .content').hide();
$('.btn_close').hide();
event.stopPropagation();
});
Related
Using Polymer 1.1, in Chrome the elements are centered when the screen is resized smaller. But in Firefox, they shift to the left.
I filed a bug for this, but in the meantime...
Is there a way of making them centered in Firefox without breaking them in Chrome?
<dom-module id="portfolio-display">
<style>
:host[show] {
#apply(--layout-horizontal);
#apply(--layout-center-justified);
height: 100%;
width: 100%;
background-color: var(--paper-grey-50);
}
#main {
width: 100%;
margin-top: 50px;
}
</style>
<template>
<template is="dom-if" if="{{show}}">
<iron-media-query query="(min-width: 900px)" query-matches="{{queryMatches}}"></iron-media-query>
<div id="main">
<div class="layout vertical center center">
<portfolio-first-row class$="{{computeMediaSize(queryMatches)}}"></portfolio-first-row>
<portfolio-second-row class$="{{computeMediaSize(queryMatches)}}"></portfolio-second-row>
<portfolio-third-row class$="{{computeMediaSize(queryMatches)}}"></portfolio-third-row>
</div>
</div>
</template>
</template>
<script>
Polymer({
is: "portfolio-display",
properties: {
show: {
type: Boolean,
reflectToAttribute: true,
value: false
}
},
toggleShow: function() {
this.show = !this.show;
},
computeMediaSize: function (smallScreen) {
if (!smallScreen) {
return "layout vertical center center";
}
}
});
</script>
</dom-module>
I would like to achieve the effect where one image is revealed over the other when scrolling the page.
You can see an example on livearealabs.com (new york / seattle). Does anybody know how to create it using CSS3?
Check out this jsfiddle to create the sliding effect.
The trick is to have one div rotated 60 degrees. You position it so that it covers the entire wrapper and the overflow is hidden. Then with javascript you just have to move the slice container either by changing the left property or by changing the translate-X property.
Here is the code:
HTML:
<div class="wrapper">
<div class="bg"></div>
<div class="slice" data-show="true"></div>
</div>
CSS:
.wrapper {
position: relative;
overflow: hidden;
width: 20em;
height: 10em;
}
.bg {
background-color: red;
width: 100%;
height: 100%;
}
.slice {
position: absolute;
top: -12em;
left: -8em;
width: 30em;
height: 30em;
background-color: blue;
-webkit-transform: rotate(-60deg);
}
JS:
var hidden = false;
$('.wrapper').click(function() {
console.log('click');
if (hidden) {
$('.slice').stop().animate({left: '-8em'}, 2000);
hidden = false;
} else {
$('.slice').stop().animate({left: '-34em'}, 2000);
hidden = true;
}
console.log('click end');
});
Also check out this jsfiddle for a similar sliding effect that can be achieved with CSS only.
With the Kendo UI editor a user can click the "insert image" button and the imagebrowser will popup.
I'd like to have the imagebrowser open when a user clicks a div - external from the editor.
How can I do this? Is it possible?
I've tried searching for ages but can't seem to find any answers.
I forgot to come back to update this post but in the end, I used the Kendo Editor and hid everything. Here's what I did and hopefully this helps someone else one day:
.k-editable-area
{
display: none;
}
.k-editor
{
width: 4% !important;
height: 28px !important;
border: none !important;
background-image: none;
display: none;
margin-left: 10px;
}
.k-window
{
display: none;
}
Javascript:
$(document).ready(function () {
$("#imgBrowser").kendoEditor({
tools: [
"insertImage"
],
imageBrowser: {
messages: {
dropFilesHere: "Drop files here"
},
transport: {
read: "/ImageBrowser/Read",
destroy: {
url: "/ImageBrowser/Destroy",
type: "POST"
},
create: {
url: "/ImageBrowser/Create",
type: "POST"
},
thumbnailUrl: "/ImageBrowser/Thumbnail",
uploadUrl: "/ImageBrowser/Upload",
imageUrl: "/ImageBrowser/Image?path={0}"
},
change: function () {
//this.value(); //Selected image URL
},
select: function () {
}
}, execute: function (e) {
},
change: function () {
},
select: function () {
//this.value(); //Selected image URL but each selection is appended... ie:
<img /> <img /> <img /> ... you need to replace all except the last one.
SetSelectedImage(this.value());
}
});
});
Then I added a link which when clicked, triggers the image browser:
<a id="imgBrowser"></a><a id="addImage" style="display: inline; cursor: pointer;
float: left; font-weight: bold">+ Add image</a>
And finally, I added the javascript to do the triggering:
$("#addImage").click(function () {
$(".k-tool-icon").trigger('click');
});
Check this out. On focus of your text box, call below jQuery script.
$('#editor').parent().parent().parent().parent().parent().parent().find('.k-insertImage').click();
you can check on this link: kendo editor.
Just call this script from your browser console.
This is a newbie question about Kendo UI draggable. I tried to look at their examples but cant really get it.
I want to make a div draggable to another position. When setting this up I can drag the div, but it disappears when released, I want it to stay in the new place. I have tried this but it doesnt work.
$('.draggable').kendoDraggable({
axis: "x",
hint: Hint,
dragstart: DragStart,
drag: Drag,
dragend: DragEnd
});
function Hint (element) {
console.log("hint");
return element;
}
function DragStart(){
console.log("dragstart");
}
function Drag(){
console.log("draging");
}
function DragEnd(event) {
console.log("dragend");
console.log(event.x.location);
$('.draggable').css({'left': event.x.location});
}
I think this is what you want, and I made a Demo for it.
$('.draggable').kendoDraggable({
hint : function (original) {
return original.clone().addClass("ob-clone");
},
dragstart: function (e) {
$(e.target).addClass("ob-hide");
}
});
$('body').kendoDropTarget({
drop: function (e) {
var pos = $(".ob-clone").offset();
$(e.draggable.currentTarget)
.removeClass("ob-hide")
.offset(pos);
}
})
.draggable {
position: absolute;
background: red;
width: 100px;
height: 100px;
vertical-align: middle;
}
.ob-hide {
display: none;
}
.ob-clone {
background: #cccccc;
}
<link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.common.min.css" rel="stylesheet"/>
<link href="http://cdn.kendostatic.com/2013.1.319/styles/kendo.default.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.1.319/js/kendo.all.min.js"></script>
<div id="drop" style="position: absolute; width: 100%; height: 100%; border: 2px solid #000000">
<div class="draggable">
Drag 1
</div>
<div class="draggable">
Drag 2
</div>
</div>
jsFiddle: http://jsfiddle.net/Wayou/fjrcw/
I have 3 divs at the bottom of the page each with a link.
what i am trying to do
when i click a link the div will slide up 400px, #maincontent will fade out and if any of the other 2 are open then they will slide down so only 1 is fully visible at a time and if none are open the #maincontent will fade back in.
I can get them to animate up and down on click event but i cant get the others to go back to there original position.
any help would be much appreciated.
html
<div class="poolbox1"><a class="poolview1" href="#"></a>content</div>
<div class="poolbox2"><a class="poolview2" href="#"></a>content</div>
<div class="poolbox3"><a class="poolview3" href="#"></a>content</div>
css
.poolview1{ float:right; margin-top:-25px; display:block; width:31px; height:31px; background-image:url(images/accept.png); background-repeat:no-repeat}
.poolbox2{width:300px; float:left; height:400px; background-color:#666666; margin-top:-20px;opacity: 0.9; filter: alpha(opacity=90);}
jquery
$(".poolview1").click(function(){
$(".poolbox1").animate({
marginTop: "-=400px",
height: "+=400px"
}, 1000);
$(".poolview1").fadeOut(1000);
$("#maincontent").fadeOut(1000);
});
$(".poolview2").click(function(){
$(".poolbox2").animate({
marginTop: "-=400px",
height: "+=400px"
}, 1000);
$(".poolview2").fadeOut(1000);
$("#maincontent").fadeOut(1000);
});
$(".poolview3").click(function(){
$(".poolbox3").animate({
marginTop: "-=400px",
height: "+=400px"
}, 1000);
$(".poolview3").fadeOut(1000);
$("#maincontent").fadeOut(1000);
});
a working demo
html
<div id="poolbox1" class="poolbox"><a id="poolview1" class="poolview" href="#">poolview1</a>content</div>
<div id="poolbox2" class="poolbox"><a id="poolview2" class="poolview" href="#">poolview2</a>content</div>
<div id="poolbox3" class="poolbox"><a id="poolview3" class="poolview" href="#">poolview3</a>content</div>
css
.poolview{float:right; display:block; width:31px; height:31px; }
.poolbox{width:150px; float:left; height:400px; background-color:#666666;opacity: 0.9; filter: alpha(opacity=90);}
jquery
$(".poolview").click(function(){
$(".poolbox").animate({
marginTop: "400px",
height: "0px"
}, 1000);
$(this).parent().animate({
marginTop: "0px",
height: "400px"
}, 1000);
$(".poolview").fadeIn(1000);
$(this).fadeOut(1000);
$("#maincontent").fadeOut(1000);
});