Своё контекстное меню на CSS3 и jQuery
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<ul class="context"> <li class="context__header">Поделиться</li> <li class="context__item context__item--twitter"><a href="#"><i class="pre entypo-twitter"> </i>Твитнуть</a></li> <li class="context__item context__item--facebook"><a href="#"><i class="pre entypo-facebook-squared"> </i>Зафейсбучить</a></li> <li class="context__item context__item--google context__item--nope"><a href="#" title="lol, not likely">Загуглплюсить</a></li> <li class="context__item context__item--pinterest"><a href="#"><i class="pre entypo-pinterest"> </i>Пнуть</a></li> <li class="context__divider"></li> <li class="context__item context__item--email"><a href="#">Рассказать друзьям</a><i class="post entypo-right-open"></i> <ul class="context context--sub"> <li class="context__item"><a href="#">Вася</a></li> <li class="context__item"><a href="#"><i class="pre entypo-check"> </i>Петчя</a></li> <li class="context__item"><a href="#">Прохор</a></li> <li class="context__item"><a href="#">Елизар</a></li> <li class="context__item"><a href="#">Афроний</a></li> </ul> </li> <li class="context__item context__item--email"><a href="#">Изобрести велосипед</a></li> </ul> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
@import "https://fonts.googleapis.com/css?family=Lato:300,300italic,700,700italic"; @import "http://weloveiconfonts.com/api/?family=entypo"; .context { font-size: 14px; color: #D0C7FF; list-style: none; margin: 0; padding: .05em .25em; border: 1px solid transparent; border-right-color: #5062c2; border-bottom-color: #5062c2; border-radius: 3px; position: absolute; min-width: 16em; z-index: 1; background: -webkit-linear-gradient(305deg,#673AB7,#3F51B5); background: linear-gradient(145deg,#673AB7,#3F51B5); box-shadow: 0 4px 14px -5px #141321; will-change: transform,opacity; -webkit-transition: opacity,visibility,-webkit-transform; transition: opacity,visibility,-webkit-transform; transition: transform,opacity,visibility; transition: transform,opacity,visibility,-webkit-transform; -webkit-transition-duration: 0.35s,0.2s,0; transition-duration: 0.35s,0.2s,0; -webkit-transition-delay: 0.08s,0s,.4s; transition-delay: 0.08s,0s,.4s; -webkit-transition-timing-function: ease; transition-timing-function: ease; -webkit-transform: rotate3d(-1,-1,0,25deg) scale(1); transform: rotate3d(-1,-1,0,25deg) scale(1); -webkit-transform-origin: 0 0; transform-origin: 0 0; opacity: 0; visibility: hidden; } .context,.context * { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; cursor: default; } .context.is-visible { opacity: 1; -webkit-transform: none; transform: none; -webkit-transition-delay: 0s,0s,0; transition-delay: 0s,0s,0; visibility: visible; } .context--sub { background: #4b4ab6; width: auto; min-width: 10em; left: 100%; top: -.4em; -webkit-transform: translateX(-0.7em); transform: translateX(-0.7em); -webkit-transition: opacity,width,min-width,visibility,-webkit-transform; transition: opacity,width,min-width,visibility,-webkit-transform; transition: transform,opacity,width,min-width,visibility; transition: transform,opacity,width,min-width,visibility,-webkit-transform; -webkit-transition-timing-function: ease; transition-timing-function: ease; -webkit-transition-duration: 0.3s,0.25s,0.15s,0.15s,.01s; transition-duration: 0.3s,0.25s,0.15s,0.15s,.01s; -webkit-transition-delay: 0.3s,0.25s,0.3s,0.3s,.35s; transition-delay: 0.3s,0.25s,0.3s,0.3s,.35s; overflow: hidden; } .context--sub .context__item { padding-left: 2em; } .context--sub i[class*="entypo-"] { -webkit-transform: translateX(-2.25em); transform: translateX(-2.25em); } .context--sub.oppositeX { right: 100%; left: auto; -webkit-transform: translateX(0.7em); transform: translateX(0.7em); } .context--sub.oppositeY { top: auto; bottom: -.4em; } .context__header,.context__item { padding-left: 2.5em; padding-right: 1.5em; padding-top: .3em; padding-bottom: .35em; } .context__header,.context__divider { margin-top: .25em; margin-bottom: .25em; border-bottom: 1px solid rgba(208,199,255,0.3); } .context__header { font-weight: 700; padding-bottom: .5em; } .context__item { border-radius: 3px; position: relative; } .context__item:not(.context__item--nope):hover { background-color: rgba(255,255,255,0.09); color: #fff; } .context__item:not(.context__item--nope):hover .context--sub { opacity: 1; -webkit-transform: translateX(0); transform: translateX(0); -webkit-transition-delay: 0.2s,0.25s,0.2s,0.2s,0; transition-delay: 0.2s,0.25s,0.2s,0.2s,0; border-radius: 0 3px 3px 3px; visibility: visible; } .context__item:last-child { margin-bottom: .25em; } .context__item:first-child { margin-top: .25em; } .context__item--nope { color: rgba(255,255,255,0.3); } .context__item--active { -webkit-animation: flash .5s ease 1; animation: flash .5s ease 1; } .context a { cursor: default; color: inherit; text-decoration: none; display: block; } .context [class*="entypo-"] { font-style: normal; position: absolute; -webkit-transform: translateX(-2em); transform: translateX(-2em); width: 2em; text-align: right; } .context [class*="entypo-"].post { -webkit-transform: translateY(-55%); transform: translateY(-55%); right: 0; top: 50%; } .context [class*="entypo-"]:before { font-family: 'entypo',sans-serif; margin-right: .5em; } @-webkit-keyframes flash { 0% { background: rgba(255,255,255,0); } 20% { background: rgba(255,255,255,0.4); } } @keyframes flash { 0% { background: rgba(255,255,255,0); } 20% { background: rgba(255,255,255,0.4); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
<script> $(function() { var $doc = $(document), $context = $(".context:not(.context--sub)"); $doc.on("contextmenu", function(e) { var $window = $(window), $sub = $context.find(".context--sub"); $sub.removeClass("oppositeX oppositeY"); e.preventDefault(); var w = $context.width(); var h = $context.height(); var x = e.clientX; var y = e.clientY; var ww = $window.width(); var wh = $window.height(); var padx = 30; var pady = 20; var fx = x; var fy = y; var hitsRight = (x + w >= ww - padx); var hitsBottom = (y + h >= wh - pady); if (hitsRight) { fx = ww - w - padx; } if (hitsBottom) { fy = wh - h - pady; } $context.css({ left: fx - 1, top: fy - 1 }); var sw = $sub.width(); var sh = $sub.height(); var sx = $sub.offset().left; var sy = $sub.offset().top; var subHitsRight = (sx + sw - padx >= ww - padx); var subHitsBottom = (sy + sh - pady >= wh - pady); if (subHitsRight) { $sub.addClass("oppositeX"); } if (subHitsBottom) { $sub.addClass("oppositeY"); } $context.addClass("is-visible"); $doc.on("mousedown", function(e) { var $tar = $(e.target); if (!$tar.is($context) && !$tar.closest( ".context").length) { $context.removeClass("is-visible"); $doc.off(e); } }); }); $context.on("mousedown touchstart", ".context__item:not(.context__item--nope)", function(e) { if (e.which === 1) { var $item = $(this); $item.removeClass("context__item--active"); setTimeout(function() { $item.addClass("context__item--active"); }, 10); } }); // hack the preview for codepenzies setTimeout(function() { $doc.trigger("contextmenu"); $context.css({ top: 120, left: 32 }).addClass("is-visible"); }, 1000); }); </script> |