Get pixels divergence of scaled element in javascript - javascript

For example I have an element e.g. image with next css:
img{
width:400;
height:285;
transition: all .3s ease;
-webkit-transition: all .3s ease;
-moz-transition: all .3s ease;
-ms-transition: all .3s ease;
-o-transition: all .3s ease;
-webkit-backface-visibility: hidden;
}
img:hover{
transform: scale(1.04,1.04);
-ms-transform: scale(1.04,1.04);
-webkit-transform: scale(1.04,1.04);
}
On this image I have absolute banner that appears on image hover and moves according to image offset position, thus on image scaling the offset of the image is changed and my banner get "zoomed" image offset instead of normal one. I'd like to calculate divergence in pixels in order to reduce this value from the absolute banner left and top css values.
I've tried this solution, but it seems to be not working properly.
Thanks for the help

Related

Up/Down picture by mouse hover

I want something like picture links in bottom of this site.Any body know whats the effect of the site or please suggest to me some javascript code example or library to make picture up/down on mouse hover and make some beautiful tooltip too.
You only need CSS, and on hover change the margin:
img {
margin-bottom: -75px;
margin-top: 20px;
padding-right: 40px;
-webkit-transition: margin 0.5s ease;
-moz-transition: margin 0.5s ease;
-o-transition: margin 0.5s ease;
-ms-transition: margin 0.5s ease;
transition: margin 0.5s ease;
}
img:hover {
margin-top: -20px;
}
This code is basically copied from the site you've provided. I would be careful by using it as is. Take it only as an example.

How can I speed up the mobile dropdown in the Bootstrap navbar?

On the mobile phone, there is a dropdown menu on the navbar. But it is far too slow.
Is it JQuery based? Or is it CSS transition based? How do I speed it up?
It is CSS transition based, try changing the height value from the transition property of this class.
.collapsing {
position: relative;
height: 0;
overflow: hidden;
-webkit-transition: height .35s ease;
-o-transition: height .35s ease;
transition: height .35s ease;
}

firefox CSS transition bug

I wrote some CSS to cause a sidebar to do a slide transition from off the page to visible when you mouse over the side of the page. The CSS is simple and involves adding/removing a class that controls the left: position of the sidebar.
#sidebarInner{
height:100%;
width:50px;
background-color:blue;
position: fixed;
-moz-transition: left .2s linear;
-webkit-transition: left .2s linear;
-o-transition: left .2s linear;
transition: left .2s linear;
z-index:2;
}
.slideLeft {
left: -100px;
}
Try the following demo on a webkit browser and on Firefox:
http://jsfiddle.net/MmFnY/7/
You'll notice on webkit, the blue colored div has the 0.2s slide left transition but on Firefox it does not. Does anyone know whats wrong with the CSS above?
In order for the transition to work you need to provide it with a default left value. Easiest way to do this is probably to give it another class for when it's inside such as:
.slideRight{
left: 0px;
}
http://jsfiddle.net/MmFnY/19/

Twitter Bootstrap modal: How to remove Slide down effect

Is there a way to change the Twitter Bootstrap Modal window animation from a slide down effect to a fadeIn or just display without the Slide? I read through the documentation here:
http://getbootstrap.com/javascript/#modals
But they don't mention any options for changing the modal body slide effects.
Just take out the fade class from the modal div.
Specifically, change:
<div class="modal fade hide">
to:
<div class="modal hide">
UPDATE: For bootstrap3, the hide class is not needed.
The modals used by the bootstrap use CSS3 to supply the effects and they can be removed by eliminating the appropriate classes from modals container div:
<div class="modal hide fade in" id="myModal">
....
</div>
As you can see this modal has a class of .fade, meaning it is set to fade in and.in, meaning it will slide in. So just remove the class related to the effect you wish to remove, which in your case is just the .in class.
Edit: Just ran some tests and it appears that that is not the case, the .in class is added by javascript, though you can modify he slideDown behavior with css like so:
.modal.fade {
-webkit-transition: none;
-moz-transition: none;
-ms-transition: none;
-o-transition: none;
transition: none;
}
Demo
If you like to have the modal fade in rather than slide in (why is it called .fade anyway?) you can overwrite the class in your CSS file or directly in bootstrap.css with this:
.modal.fade{
-webkit-transition: opacity .2s linear, none;
-moz-transition: opacity .2s linear, none;
-ms-transition: opacity .2s linear, none;
-o-transition: opacity .2s linear, none;
transition: opacity .2s linear, none;
top: 50%;
}
If you don't want any effect just remove the fade class from the modal classes.
I believe that most of these answers are for bootstrap 2. I ran into the same issue for bootstrap 3 and wanted to share my fix. Like my previous answer for bootstrap 2, this will still do an opacity fade, but will NOT do the slide transition.
You can either change the modals.less or the theme.css files, depending on your workflow. If you haven't spent any quality time with less, I'd highly recommend it.
for less, find the following code in MODALS.less
&.fade .modal-dialog {
.translate(0, -25%);
.transition-transform(~"0.3s ease-out");
}
&.in .modal-dialog { .translate(0, 0)}
then change the -25% to 0%
Alternatively, if you're using just the css, find the following in theme.css:
.modal.fade .modal-dialog {
-webkit-transform: translate(0, -25%);
-ms-transform: translate(0, -25%);
transform: translate(0, -25%);
-webkit-transition: -webkit-transform 0.3s ease-out;
-moz-transition: -moz-transform 0.3s ease-out;
-o-transition: -o-transform 0.3s ease-out;
transition: transform 0.3s ease-out;
}
and then change the -25% to 0%.
I solved this by overriding the default .modal.fade styles in my own LESS stylesheet:
.modal {
&.fade {
.transition(e('opacity .3s linear'));
top: 50%;
}
&.fade.in { top: 50%; }
}
This keeps the fade in / fade out animation but removes the slide up / slide down animation.
I have found the best solution that removes the slide but leaves the fade is by adding the following css in a css file of your chosing which is invoked after the bootstrap.css
.modal.fade .modal-dialog
{
-moz-transition: none !important;
-o-transition: none !important;
-webkit-transition: none !important;
transition: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
-o-transform: none !important;
-webkit-transform: none !important;
transform: none !important;
}
I didn't like the slide effect either. To fix this all you have to do is make the the top attribute the same for both .modal.fade and modal.fade.in. You can take off the top 0.3s ease-out in the transitions too, but it doesn't hurt to leave it in. I like this approach because the fade in/out works, it just kills the slide.
.modal.fade {
top: 20%;
-webkit-transition: opacity 0.3s linear;
-moz-transition: opacity 0.3s linear;
-o-transition: opacity 0.3s linear;
transition: opacity 0.3s linear;
}
.modal.fade.in {
top: 20%;
}
If you're looking for a bootstrap 3 answer, look here
Just remove the fade class and if you want more animations to be perform on the Modal just use animate.css classes in your Modal.
you can also overwrite bootstrap.css by simply removing "top:-25%;"
once removed, the modal will simply fade in and out without the slide animation.
look at http://quickrails.com/twitter-bootstrap-modal-how-to-remove-slide-down-effect-but-leaves-the-fade/
.modal.fade .modal-dialog
{
-moz-transition: none !important;
-o-transition: none !important;
-webkit-transition: none !important;
transition: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
-o-transform: none !important;
-webkit-transform: none !important;
transform: none !important;
}
I'm working with bootstrap 3 and the Durandal JS 2 modal plugin. This question was on top of Google results and as none of the answers above is working for me I thought I'd share my solution for future visitors.
I override the default Bootstrap's Less code with this in my own less:
.modal {
&.fade .modal-dialog {
.translate(0, 0);
.transition-transform(~"none");
}
&.in .modal-dialog { .translate(0, 0)}
}
That way I am left with only the fade effect, and no slideDown.
.modal.fade, .modal.fade .modal-dialog {
-webkit-transition: none;
-moz-transition: none;
-ms-transition: none;
-o-transition: none;
transition: none;
}
The question was clear: remove only the slide: Here is how to change it in Bootstrap v3
In modals.less comment out the translate statement:
&.fade .modal-dialog {
// .translate(0, -25%);
just remove 'fade' class from modal class
class="modal fade bs-example-modal-lg"
as
class="modal bs-example-modal-lg"
Wanted to update this. Most of you have not completed this issue. I'm using Bootstrap 3. none of the fixes above worked.
to remove the slide effect but keep the fade in. I went into bootstrap css and (noted out the following selectors) - this resolved the issue.
.modal.fade .modal-dialog{/*-webkit-transform:translate(0,-25%);-ms-transform:translate(0,-25%);transform:translate(0,-25%);-webkit-transition:-webkit-transform .3s ease-out;-moz-transition:-moz-transform .3s ease-out;-o-transition:-o-transform .3s ease-out;transition:transform .3s ease-out*/}
.modal.in .modal-dialog{/*-webkit-transform:translate(0,0);-ms-transform:translate(0,0);transform:translate(0,0)*/}
The following CSS works for me - Using Bootstrap 3.
You need to add this css after boostrap styles -
.modal.fade .modal-dialog{
-webkit-transition-property: transform;
-webkit-transition-duration:0 ;
transition-property: transform;
transition-duration:0 ;
}
.modal.fade {
transition: none;
}

change class based on page scroll

Basically I have a single page site that scrolls when the user clicks on the navigation menu.
<div id="mainnav">
<ul id="nav">
<li class="fadertwo"><a id="tst" onclick="CngClass(this);" href="index.html#abouttwo">About</a></li>
<li class="faderthree"><a id="sec" onclick="CngClass(this);" href="index.html#second">Curriculum vitae</a></li>
<li class="faderfour"><a id="third" onclick="CngClass(this);" href="index.html#thirdtwo">contact</a></li>
</ul>
</div> <!-- end mainnav -->
Using jquery (which im totally new to) it adds a class when the user clicks on each link.
Basically it transitions the background position.
.active {
background-position:bottom;
text-decoration:none;
-webkit-transition: .3s linear;
-moz-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
}
Background is a 10px img repeating along the top.
#tst {background-image:url(../_images/whiteb.png);
background-repeat:repeat-x;
-webkit-transition: .3s linear;
-moz-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
}
#sec {background-image:url(../_images/blackb.png);
background-repeat:repeat-x;
-webkit-transition: .3s linear;
-moz-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;
}
#third {background-image:url(../_images/greenb.png);
background-repeat:repeat-x;
-webkit-transition: .3s linear;
-moz-transition: .3s linear;
-o-transition: .3s linear;
transition: .3s linear;}
Now the jquery magic -
<script type="text/javascript">
var Lst;
function CngClass(obj){
if (typeof(obj)=='string') obj=document.getElementById(obj);
if (Lst) Lst.className='';
obj.className='active';
Lst=obj;
}
</script>
It works great changing the background position in a really smooth way when the user clicks it, but of course doesn't change based on the user scrolling the page naturally.
Now, I could set the body overflow to :hidden; and 'fix' that, but it's a bit hacky and will limit the content area and overall site layout.
What I'd like to do is use jquery to add the class .active to the a tag based on scroll position so it changes anyway.
I've looked around for hours and tried different things but my (lackof) knowledge of jquery limits me somewhat it implementing anything I find effectively.
Can anyone offer any solution?
Have a look at scrollspy
http://twitter.github.com/bootstrap/javascript.html#scrollspy
or
https://github.com/sxalexander/jquery-scrollspy
Or have a look at
http://imakewebthings.com/jquery-waypoints/

Categories

Resources