PageSourceSearch

https://loxblog.com/asset/js/home/header.js

js loxblog.com collected 2026-10-04 20:56:46 UTC 13,400 bytes, 735 lines download raw bytes

1
2/* =========================================================
3   Moving Balloon
4   فقط موقعیت بالون تغییر می‌کند.
5   اندازه و opacity بالون هرگز توسط JavaScript تغییر نمی‌کند.
6========================================================= */
7
8$(document).ready(function () {
9
10    // شروع حرکت بالن
11    animateDiv();
12
13});
14
15
16function makeNewPosition() {
17
18    var container = document.getElementById("container");
19    var balloon = document.querySelector(".a");
20
21    if (!container || !balloon) {
22        return [0, 0];
23    }
24
25    var containerWidth = container.clientWidth;
26    var containerHeight = container.clientHeight;
27
28    var balloonWidth = balloon.offsetWidth;
29    var balloonHeight = balloon.offsetHeight;
30
31    // محدوده امن
32    var maxLeft = Math.max(0, containerWidth - balloonWidth);
33    var maxTop = Math.max(0, containerHeight - balloonHeight);
34
35    /*
36     * فقط یک حرکت کوچک از موقعیت فعلی
37     * تا بالن ناگهان به نقطه دیگری نپرد.
38     */
39    var currentLeft = parseFloat($(balloon).position().left) || 0;
40    var currentTop = parseFloat($(balloon).position().top) || 0;
41
42    var moveX = 40 + Math.random() * 80;
43    var moveY = 15 + Math.random() * 40;
44
45    // جهت تصادفی
46    if (Math.random() < 0.5) {
47        moveX = -moveX;
48    }
49
50    if (Math.random() < 0.5) {
51        moveY = -moveY;
52    }
53
54    var newLeft = currentLeft + moveX;
55    var newTop = currentTop + moveY;
56
57    // جلوگیری از خروج از کادر
58    newLeft = Math.max(0, Math.min(newLeft, maxLeft));
59    newTop = Math.max(0, Math.min(newTop, maxTop));
60
61    return [newTop, newLeft];
62}
63
64
65function animateDiv() {
66
67    var balloon = $(".a");
68
69    if (!balloon.length) {
70        return;
71    }
72
73    var newPosition = makeNewPosition();
74
75    var currentPosition = balloon.position();
76
77    var currentTop = currentPosition.top || 0;
78    var currentLeft = currentPosition.left || 0;
79
80    var distance = Math.sqrt(
81        Math.pow(newPosition[1] - currentLeft, 2) +
82        Math.pow(newPosition[0] - currentTop, 2)
83    );
84
85    // سرعت طبیعی و کمی تصادفی
86    var speed = 2500 + (distance * 8) + Math.random() * 1800;
87
88    balloon.stop(true, false).animate(
89        {
90            top: newPosition[0],
91            left: newPosition[1]
92        },
93        {
94            duration: speed,
95            easing: "swing",
96
97            complete: function () {
98
99                // مکث کوتاه و سپس حرکت بعدی
100                setTimeout(function () {
101                    animateDiv();
102                }, 400 + Math.random() * 1200);
103
104            }
105        }
106    );
107}
108
109
110function calcSpeed(prev, next) {
111
112    var x = Math.abs(
113        prev[1] - next[1]
114    );
115
116    var y = Math.abs(
117        prev[0] - next[0]
118    );
119
120    var greatest = Math.max(x, y);
121
122    var speedModifier = 0.1;
123
124    /*
125     * حداقل زمان حرکت:
126     * باعث می‌شود بالون ناگهان جابه‌جا نشود.
127     */
128
129    return Math.max(
130        1000,
131        Math.ceil(greatest / speedModifier)
132    );
133}
134
135
136/* =========================================================
137   Desktop Hover Menu
138========================================================= */
139
140$(document).ready(function () {
141
142    if (window.innerWidth > 768) {
143
144        $(".move").hover(
145
146            function () {
147
148                $(this)
149                    .stop(true, false)
150                    .animate(
151                        {
152                            paddingTop: "0px"
153                        },
154                        200
155                    );
156
157            },
158
159            function () {
160
161                $(this)
162                    .stop(true, false)
163                    .animate(
164                        {
165                            paddingTop: "10px"
166                        },
167                        100
168                    );
169
170            }
171
172        );
173
174    }
175
176});
177
178
179/* =========================================================
180   Canvas / Pixie
181========================================================= */
182
183var WIDTH = 0;
184var HEIGHT = 0;
185
186var canvas = null;
187var con = null;
188
189var pxs = [];
190
191var rint = 60;
192
193
194function resizeCanvas() {
195
196    if (!canvas || !con) {
197        return;
198    }
199
200    var container = document.getElementById("container");
201
202    if (!container) {
203        return;
204    }
205
206    /*
207     * اندازه Canvas از container گرفته می‌شود.
208     * خود container توسط JavaScript تغییر اندازه نمی‌دهد.
209     */
210
211    WIDTH = container.clientWidth;
212    HEIGHT = container.clientHeight;
213
214    if (WIDTH <= 0 || HEIGHT <= 0) {
215        return;
216    }
217
218    var dpr = window.devicePixelRatio || 1;
219
220    canvas.width = Math.round(
221        WIDTH * dpr
222    );
223
224    canvas.height = Math.round(
225        HEIGHT * dpr
226    );
227
228    /*
229     * اندازه ظاهری Canvas ثابت می‌ماند.
230     */
231
232    canvas.style.width =
233        WIDTH + "px";
234
235    canvas.style.height =
236        HEIGHT + "px";
237
238    con.setTransform(
239        dpr,
240        0,
241        0,
242        dpr,
243        0,
244        0
245    );
246}
247
248
249/*
250 * راه‌اندازی Canvas
251 */
252
253$(document).ready(function () {
254
255    canvas =
256        document.getElementById("pixie");
257
258    if (!canvas) {
259        return;
260    }
261
262    con =
263        canvas.getContext("2d");
264
265    if (!con) {
266        return;
267    }
268
269    resizeCanvas();
270
271    pxs = [];
272
273    for (var i = 0; i < 50; i++) {
274
275        pxs[i] = new Circle();
276
277        pxs[i].reset();
278
279    }
280
281    animate();
282
283});
284
285
286/*
287 * تغییر اندازه صفحه
288 */
289
290$(window).on("resize", function () {
291
292    resizeCanvas();
293
294});
295
296
297/*
298 * انیمیشن Canvas
299 */
300
301function animate() {
302
303    if (!con) {
304        return;
305    }
306
307    draw();
308
309    requestAnimationFrame(
310        animate
311    );
312
313}
314
315
316/*
317 * رسم Canvas
318 */
319
320function draw() {
321
322    if (!con) {
323        return;
324    }
325
326    con.clearRect(
327        0,
328        0,
329        WIDTH,
330        HEIGHT
331    );
332
333    for (
334        var i = 0;
335        i < pxs.length;
336        i++
337    ) {
338
339        pxs[i].fade();
340
341        pxs[i].move();
342
343        pxs[i].draw();
344
345    }
346
347}
348
349
350/* =========================================================
351   Circle
352========================================================= */
353
354function Circle() {
355
356    this.s = {
357
358        ttl: 9000,
359
360        xmax: 5,
361
362        ymax: 2,
363
364        rmax: 20,
365
366        rt: 10,
367
368        xdef: 90,
369
370        ydef: 50,
371
372        xdrift: 4,
373
374        ydrift: 4,
375
376        random: true,
377
378        blink: true
379
380    };
381
382
383    this.reset = function () {
384
385        this.x =
386            this.s.random
387                ? WIDTH * Math.random()
388                : this.s.xdef;
389
390
391        this.y =
392            this.s.random
393                ? HEIGHT * Math.random()
394                : this.s.ydef;
395
396
397        this.r =
398            (
399                (this.s.rmax - 1)
400                * Math.random()
401            ) + 1;
402
403
404        this.dx =
405            (
406                Math.random()
407                * this.s.xmax
408            )
409            *
410            (
411                Math.random() < 0.5
412                    ? -1
413                    : 1
414            );
415
416
417        this.dy =
418            (
419                Math.random()
420                * this.s.ymax
421            )
422            *
423            (
424                Math.random() < 0.5
425                    ? -1
426                    : 1
427            );
428
429
430        this.hl =
431            (
432                this.s.ttl / rint
433            )
434            *
435            (
436                this.r /
437                this.s.rmax
438            );
439
440
441        this.rt =
442            Math.random()
443            * this.hl;
444
445
446        this.s.rt =
447            Math.random() + 1;
448
449
450        this.stop =
451            Math.random() * 0.2 + 0.4;
452
453    };
454
455
456    this.fade = function () {
457
458        this.rt += this.s.rt;
459
460    };
461
462
463    this.draw = function () {
464
465        if (
466            this.s.blink &&
467            (
468                this.rt <= 0 ||
469                this.rt >= this.hl
470            )
471        ) {
472
473            this.s.rt =
474                this.s.rt * -1;
475
476        }
477
478        else if (
479            this.rt >= this.hl
480        ) {
481
482            this.reset();
483
484        }
485
486
487        var newo =
488            1 -
489            (
490                this.rt /
491                this.hl
492            );
493
494
495        /*
496         * جلوگیری از مقدار نامعتبر opacity
497         */
498
499        newo =
500            Math.max(
501                0,
502                Math.min(
503                    1,
504                    newo
505                )
506            );
507
508
509        con.beginPath();
510
511
512        con.arc(
513            this.x,
514            this.y,
515            this.r,
516            0,
517            Math.PI * 2,
518            true
519        );
520
521
522        con.closePath();
523
524
525        var cr =
526            this.r * newo;
527
528
529        var g =
530            con.createRadialGradient(
531                this.x,
532                this.y,
533                0,
534                this.x,
535                this.y,
536                cr <= 0 ? 1 : cr
537            );
538
539
540        g.addColorStop(
541            0.0,
542            "rgba(255,255,255," +
543            newo +
544            ")"
545        );
546
547
548        g.addColorStop(
549            this.stop,
550            "rgba(210,230,255," +
551            (newo * 0.6) +
552            ")"
553        );
554
555
556        g.addColorStop(
557            1.0,
558            "rgba(210,230,255,0)"
559        );
560
561
562        con.fillStyle = g;
563
564        con.fill();
565
566    };
567
568
569    this.move = function () {
570
571        this.x +=
572            (
573                this.rt /
574                this.hl
575            )
576            *
577            this.dx;
578
579
580        this.y +=
581            (
582                this.rt /
583                this.hl
584            )
585            *
586            this.dy;
587
588
589        if (
590            this.x > WIDTH ||
591            this.x < 0
592        ) {
593
594            this.dx *= -1;
595
596        }
597
598
599        if (
600            this.y > HEIGHT ||
601            this.y < 0
602        ) {
603
604            this.dy *= -1;
605
606        }
607
608    };
609
610}
611
612
613/* =========================================================
614   Background Position
615========================================================= */
616
617$(function () {
618
619    $("#a a")
620
621        .css({
622            backgroundPosition:
623                "3px -35px"
624        })
625
626        .mouseover(function () {
627
628            $(this)
629                .stop(true, false)
630                .animate(
631                    {
632                        backgroundPosition:
633                            "(3px 0px)"
634                    },
635                    {
636                        duration: 500
637                    }
638                );
639
640        })
641
642        .mouseout(function () {
643
644            $(this)
645                .stop(true, false)
646                .animate(
647                    {
648                        backgroundPosition:
649                            "(3px -35px)"
650                    },
651                    {
652                        duration: 100,
653
654                        complete: function () {
655
656                            $(this).css({
657                                backgroundPosition:
658                                    "3px -35px"
659                            });
660
661                        }
662
663                    }
664                );
665
666        });
667
668});
669
670
671/* =========================================================
672   Rounded Images
673========================================================= */
674
675$(document).ready(function () {
676
677    $(".rounded-img, .rounded-img2").on(
678        "load",
679        function () {
680
681            var image = $(this);
682
683            /*
684             * اگر تصویر قبلاً wrap شده،
685             * دوباره wrap نشود.
686             */
687
688            if (
689                image.parent().hasClass(
690                    image.attr("class")
691                )
692            ) {
693                return;
694            }
695
696
697            var imageWidth =
698                image.width();
699
700            var imageHeight =
701                image.height();
702
703
704            image.wrap(function () {
705
706                return (
707                    '<span class="' +
708                    image.attr("class") +
709                    '" style="' +
710                    'background:url(' +
711                    image.attr("src") +
712                    ') no-repeat center center;' +
713                    'width:' +
714                    imageWidth +
715                    'px;' +
716                    'height:' +
717                    imageHeight +
718                    'px;' +
719                    'display:inline-block;' +
720                    '"></span>'
721                );
722
723            });
724
725
726            image.css(
727                "opacity",
728                "0"
729            );
730
731        }
732    );
733
734});
735

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.